VBA reference to external workbook not working - HELP!

A

Ashleigh

Hello All,

I have been unable to make the following code (intended to pull a
value from an external worksheet) work:

Sub macro1()

Dim wkbk As Workbook
Dim wks As Worksheet
Dim rng As Range
Dim s1 As String



s1 = Cells(2, 4).Value
'the value in cells(2,4) is "BA32004.xls" (with the quotes)
'this workbook reference will change and so I cannot hardcode it into
the macro

Set wkbk = Workbooks(s1)
'I've referenced a string as a workSHEET name in the past and it has
worked, but it doesn't seem to be functioning as a workbook name.

Set wks = wkbk.Worksheets("File_Maint")

Set rng = wks.Range("c10")

Cells(5, 5).Value = rng.Value


End Sub

I realize that all of this could be accomplished without vba, using
the indirect function, but I am trying to create a workbook that will
operate entirely on macros. I just can't figure out what I'm doing
wrong here. Any help would be appreciated tremendously. Thanks in
advance,

Ashleigh
 

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