Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why is this small piece of code failing?

Status
Not open for further replies.

Zac5

Programmer
Jan 30, 2003
75
US
Dear All,

The following fails at line "Master_wb.Activate":

Dim Master_wb As Workbook

Workbooks.Open Filename:=ws.Cells(rrng, 1)
Set Master_wb = ActiveWorkbook
Workbooks.Open Filename:=ws.Cells(rrng, 2)

Master_wb.Activate
Sheets("Expenses").Select

What am I doing wrong please?
 
The following fails
Any error message ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 


Hi,

Best to do this...
Code:
  Dim Master_wb As Workbook, wbOther as workbook

  Set Master_wb = Workbooks.Open(Filename:=ws.Cells(rrng, 1))

  set wbOther = Workbooks.Open(Filename:=ws.Cells(rrng, 2))

  with Master_wb.Sheets("Expenses")
    'you do not need to ACTIVATE or SELECT to work on these objects
[b]
    .Cells(1,1).value = "This is a text that puts a value into the master workbook, sheet Expenses, A1"
[/b]
  end with

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I have managed to resolve this problem. You cannot see from the code snippet I gave but I made a basic mistake of decalring a parameter locally within a procedure and should have declared it outside, globally. Thanks to those who have tried to help. This issue is now resolved.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top