VBA workbook_Open problem

sthyne

New Member
Joined
Jun 25, 2018
Messages
6
I am looking for vba to prevent workbook_open from executing in new save as file without changing the original file. I have a template that I open with a workbook_Open module to auto generate a sequential number. I want to save the new file to a different location with a new name but I dont want the new file to execute the workbook_Open module. Everything I try ends up changing the template as well.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
.
It would help a lot to see your code.
 
Upvote 0
.
It would help a lot to see your code.
Private Sub Workbook_Open()
'Step 1: Protect the sheet with a password
Sheets("PG S7 Reaction Tank #210").Unprotect Password:="4848"
Worksheets("PG S7 Reaction Tank #210").Range("l23") = Worksheets("PG S7 Reaction Tank #210").Range("l23") + 1
'Step 2: Protect the sheet with a password
Sheets("PG S7 Reaction Tank #210").Protect Password:="4848"
End Sub

Private Sub CommandButton17_Click()


Dim Path As String
Dim filename1 As String


Path = "N:\BKEP Materials Grand Island\Lab\2018 Production Batch Sheets-Log\Available PMAC Batch Sheets\PG S7"
filename1 = Range("A201").Text
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=Path & filename1 & ".xlsm", FileFormat:=52
Application.DisplayAlerts = True
ActiveWorkbook.Close
End Sub
 
Upvote 0
.
What is the path (location) where you want the file to be saved ?

What is the extension of the file now (.xlsx ; .xlsm ; .xlsb ??? )
 
Upvote 0
.
Try this ... paste into a Routine Module with CommandButton on the worksheet to activate it.

Code:
Option Explicit


Sub SaveBookAs()


Dim Path As String
Dim filename1 As String


Path = "C:\Users\My\Desktop\"   '<-- edit path as required
filename1 = Range("A1").Text


Application.DisplayAlerts = False


    ActiveWorkbook.SaveAs Filename:=Path & filename1 & ".xlsm"
    
Application.DisplayAlerts = True


Application.Quit
Application.Visible = False


End Sub

You will need to delete the Workbook_Open macro.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top