Write To And Retrieve From Another Workbook With VBA Code

  • Thread starter Thread starter Minitman
  • Start date Start date
M

Minitman

Greetings.

I am working in one workbook that I'll call wb1. I am storing the
data into another workbook that I'll call wb2. I am both writing data
to wb2 from a UserForm (using VBA) and getting data from and loading
it into wb1 to modify, then add back into wb2 as a new record.

I do not know how to access another workbook with VBA. I can access
another workbook with a formula in a cell, but the syntax is different
in VBA.

Could someone show me the way?

TIA

-Minitman
 
Hi
you may try something like the following:
sub foo()
dim wbk1 as workbook
dim wbk2 as workbook

set wbk1 = activeworkbook
set wbk2 = workbooks("book2")

wbk2.worksheets("Sheet1").range("A1").value = "test it"
wbk2.activate
wbk2.worksheets("Sheet1").activate
msgbox "Workbook 2 / sheet 1 is activated"
wbk1.activate
msgbox "and back again"
end sub
 
Hey Frank,

Thank you for this solution, it looks like something that I can use to
make the conversion much easier.

I really appreciate the help.

-Minitman


On Fri, 12 Mar 2004 09:46:08 +0100, "Frank Kabel"
Hi
you may try something like the following:
sub foo()
dim wbk1 as workbook
dim wbk2 as workbook

set wbk1 = activeworkbook
set wbk2 = workbooks("book2")

wbk2.worksheets("Sheet1").range("A1").value = "test it"
wbk2.activate
wbk2.worksheets("Sheet1").activate
msgbox "Workbook 2 / sheet 1 is activated"
wbk1.activate
msgbox "and back again"
end sub
 
Back
Top