1

I very recently got into VBA coding, however, even though the code compiles without any hiccups, it still fails to do it's intended purpose. Essentially, this is merely a test program created to copy and paste information from one workbook to another in a specific cell.

Sub CopyOpenItems()

   ' CopyOpenItems Macro  
   ' Copy open items to sheet.  
   ' Keyboard Shortcut: Ctrl+Shift+O  
   '  
   Dim wbTarget As Workbook 'workbook where the data is to be pasted  
   Dim wbThis As Workbook 'workbook from where the data is to copied  
   Dim wsTarget As Worksheet  
   Dim wsThis As Worksheet  
   Dim strName As String   'name of the source sheet/ target workbook  

   'set to the current active workbook (the source book)  
   Set wbThis = ActiveWorkbook  

   'get the active sheetname of the book 
   strName = ActiveSheet.Name  

   'open target workbook  
   Set wbTarget = Workbooks.Open("C:\Users\Administrator\Desktop\Excel Testing\Excel Info Testing 2.xlsx")  

   'set variable to current worksheet  
   Set wsThis = ActiveSheet  

   'set variable to target worksheet 
   Set wsTarget = wbTarget.Worksheets(strName)  

   wsThis.Range("C6").Select  

   'clear any thing on clipboard to maximize available memory 
   Application.CutCopyMode = False  

   'copy the range from source book  
   wsThis.Range("C6").Copy  

   'paste the data on the target book  
   wsTarget.Range("E5").PasteSpecial  

   'clear any thing on clipboard to maximize available memory  
   Application.CutCopyMode = False  

   'save the target book  
   wbTarget.Save  

   'close the workbook  
   wbTarget.Close  

   'clear memory  
   Set wbTarget = Nothing  
   Set wbThis = Nothing  

End Sub
Will Cheng
  • 33
  • 6
  • Sorry Jeeped, I actually modified a bit of your code and MY code did not work. – Will Cheng Jan 06 '16 at 05:21
  • Your's by itself worked perfectly fine – Will Cheng Jan 06 '16 at 05:22
  • Hi Jeeped, sorry I'm new to this forum and I'm unsure how to personally message you for questions. Is it possible for you to go over quickly how for loops work in VBA? Also, is there a function that can select the right cell adjacent to the currently selected cell? Lastly, is there a way to run the program in which I have posted by having the USER select the cell in which the information is to be extracted from? – Will Cheng Jan 06 '16 at 05:27
  • Hi, this worked for me like a charm. Some checking might be needed. Take it as a help to google around these class and function names `Const source As String = "\\...some...path...to...server...file.xlsm" Set ext_wb = Workbooks.Open(source) ThisWorkbook.Sheets("SOURCESHEET").Range("D1:H1").Copy ext_wb.Sheets("TARGETSHEET").Range("D1:H1").PasteSpecial Paste:=xlPasteValues` – AirUp Jan 06 '16 at 05:33
  • Thanks a bunch Curzon! – Will Cheng Jan 06 '16 at 05:35

0 Answers0