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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select a workbook in Excel

Status
Not open for further replies.

nberryman

Instructor
Joined
Jun 1, 2002
Messages
556
Location
GB
I have a macro that updates a sheet in a workbook. It works fine in the workbook but I need to send it to a friend who then needs to run it on a number of workbooks all with different names. I don't think her skills will allow me to talk her through the copy/paste process.

How can I select a workbook and then have the macro in my update workbook run on the newly opened workbook and not the one I will be sending out.

I keep getting an error.

Hope this is clear Neil Berryman
IT Trainer
neil_berryman@btopenworld.com
 
Probably best to post the code. Whatever I say here is speculative. Really need to look at the code.

We would be looking for any "ThisWorkbook" references. Those need to go. Replace them all with "ActiveWorkbook". Of course, others may have other ideas, but this is what I am suggesting.

Put the code in an empty workbook, mail it to her.
She would have the target book active, go to Tools-Macros. She would run the macro from that dialog. Shouldn't be too daunting, the Macros dialog is a user-oriented dialog.

Like I said, post the code. We will take it from there.

Steve
 
The code is below, as I say it works if I copy and paste the code into the workbook I want to change but if I run it from another workbook I get a Subscript out of range error

Thanks for your help



Sub Update_Summary()
'
' Update_Summary Macro
'
Sheets("Summary 03").Select
ActiveSheet.Unprotect ("Louise")

'
Range("D3").Select
ActiveCell.FormulaR1C1 = "=SUM(April:March!R[8]C[33])"
Range("E3").Select
ActiveCell.FormulaR1C1 = "=SUM(April:March!R[8]C[33])"
Range("F3").Select
ActiveCell.FormulaR1C1 = "=SUM(April:March!R[8]C[35])"
Range("F3").Select
Selection.AutoFill Destination:=Range("F3:M3"), Type:=xlFillDefault
Range("F3:M3").Select
Range("B3:M3").Select
ActiveWindow.SmallScroll ToRight:=3
Selection.AutoFill Destination:=Range("B3:M100"), Type:=xlFillDefault
Range("B3:M100").Select
Range("A1").Select

ActiveSheet.Protect ("Louise")


MsgBox ("Summary Sheet Updated")


End Sub
Neil Berryman
IT Trainer
neil_berryman@btopenworld.com
 
Sub Update_Summary()
'
' Update_Summary Macro
'
You may want to have her manually unprotect the sheet, and manually ensure the correct sheet is selected
If you do that, you can remove/comment the next two lines
Sheets("Summary 03").Select Does this exist?
ActiveSheet.Unprotect ("Louise")Is this the correct password?

'
Range("D3").Select
ActiveCell.FormulaR1C1 = "=SUM(April:March!R[8]C[33])"
Range("E3").Select
ActiveCell.FormulaR1C1 = "=SUM(April:March!R[8]C[33])"
Range("F3").Select
ActiveCell.FormulaR1C1 = "=SUM(April:March!R[8]C[35])"
Range("F3").Select
Selection.AutoFill Destination:=Range("F3:M3"), Type:=xlFillDefault
Range("F3:M3").Select
Range("B3:M3").Select
ActiveWindow.SmallScroll ToRight:=3
Selection.AutoFill Destination:=Range("B3:M100"), Type:=xlFillDefault
Range("B3:M100").Select
Range("A1").Select

Get rid of this, if the other two lines were deleted/commented out
ActiveSheet.Protect ("Louise") Is this the correct password?


MsgBox ("Summary Sheet Updated")


End Sub
 
I think I will go with the manual unprotect as you say

Many thanks

Neil Berryman
IT Trainer
neil_berryman@btopenworld.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top