Help in Pasting from 1 workbook to another in code

G

Guest

I am using VBA code in Access to paste 1 column from workbook 1 to workbook 2.

This is the code that works by itself:

xlApp.Workbooks.Open(pathS).Worksheets("an_fb_diff").Range("A2:A237").Copy
destination:=xlApp.Workbooks.Open(path).Worksheets("an_fb").Range("A3")

I am unable to following it by another one because I am using the Open. I
wish to repeat the pasting from a different worksheet.

Can someone help me in indicating what I should replace the Open with????

I tried:

xlApp.Workbooks(pathS).Worksheets("cntl_fb_diff").Range("A2:A110").Copy
destination:=xlApp.Workbooks(path).Worksheets("cntl_fb").Range("A3")

The above gives me an error!!!

Help is deeply appreciated!!!


Gary
 
T

Tim Williams

dim wb as object, wb2 as object

set wb=xlApp.Workbooks.Open(path1)
set wb2=xlApp.Workbooks.Open(path2)

wb1.Worksheets("an_fb_diff").Range("A2:A237").Copy _
destination:=wb2.Worksheets("an_fb").Range("A3")

Tim
 
M

Mbt6

Someone out there smarter than me probably has a better way...

could you try something like

ActiveWindow.ActivateNext

this is realy assuming you have only two workbooks open, and it's simlpy the
vba code for Ctrl-F6, which just toggles to the next open workbook....if you
only have two open, use this a few times to toggle back and forth where
needed...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top