Workbook_open is not saving my workbook

L

Legacy 243189

Guest
Hello,
I came into an issue while setting up macro on a workbook i have.

the issue is i need the following sets of actions to be completed when the workbook got opened programmitcally :

save workbook
and save as pdf.

below the macro i have

Private Sub Workbook_Open()
ActiveWorkbook.Save
Basma

End Sub
Sub Basma()

ThisWorkbook.Save


ChDir "C:\NOC_Automation\Parser Reports\Count Reports"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\NOC_Automation\Parser Reports\Count Reports\NOC Weekly Trend Reports.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False


End Sub

the thing is .. when i opened the workbook and close it i got the message do you want to save changes..
this message doesn't suppose to appear cause i already saved the workbook.

Please advise where i got this macro wrong.

thanks,
Basma
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
My excel sheet get updated as soon it got opened .. I need to save the new changed values.

Please advise.
 
Upvote 0
Private Sub Workbook_Open()
Application.Calculate
ThisWorkbook.Save
Basma
End Sub

?
Although, I'm guessing the pdf export changes some workbook properties
 
Upvote 0
Hello drgs and thank you.

I have tried the above macro which you have provided above, but this didn't solve my problem ...this open event .. seems not to save my work.

Please advise.
 
Upvote 0
Private Sub Workbook_Open()
Application.Calculate
ThisWorkbook.Save
ThisWorkbook.ChangeFileAccess Mode:=xlReadOnly
Basma
End Sub

?
 
Upvote 0
Thank you drgs.. that worked perfectly for the save thing.. but not the save as pdf.. please help.
 
Upvote 0
What is wrong exactly?

Private Sub Workbook_Open()
Application.Calculate
ThisWorkbook.Save
ThisWorkbook.ChangeFileAccess Mode:=xlReadOnly
Basma
ThisWorkbook.Close SaveChanges:=False
End Sub
 
Upvote 0
Hello drgs and appreciated your help alot!

below the latest macro :

Private Sub Workbook_Open()
ThisWorkbook.RefreshAll
Application.Calculate
ThisWorkbook.Save
Sheets("Monthly Trend Report").Select
ChDir "C:\NOC_Automation\Parser Reports\Count Reports"
Sheets("Monthly Trend Report").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\NOC_Automation\Parser Reports\Count Reports\NOC Monthly Trend Report.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False

End Sub

The issue is when i opened the excel sheet ,the macro run and now the excel is saved and got saved as PDF as well.
but when I fire the open event through batch file, the PDF which is saved by the macro , it is not the most updated.. and it seems the macro never ran when opening the file through the batch file.

it looks like an issue. with opening the excel programmatically


again thank you ..you helped me alot with the above macro.
 
Upvote 0

Forum statistics

Threads
1,215,577
Messages
6,125,637
Members
449,242
Latest member
Mari_mariou

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