Troubleshoot private sub workbook_open()

untern8

New Member
Joined
Apr 23, 2012
Messages
19
I have some code that automatically generates a filename with today's date from a template file. The code works great IFF excel is completely closed. If any workbooks are open, the code simply does not run.

Here's a sample of my code:


Code:
Option ExplicitPrivate Sub Workbook_Open()
    AddDate
    filename_cellvalue
    OpenPtNames
            
End Sub




Sub AddDate()
    Range("A1").Select
    ActiveCell.Value = Date
    Range("A3").Select
End Sub



Sub filename_cellvalue()
Dim Path As String
Dim filename As String
Path = "C:\Users\nunterseher.JCC\Desktop\"
filename = Range("d1").Value & ".xlsx"
ActiveWorkbook.SaveAs Path & filename, xlOpenXMLWorkbook
End Sub




Sub OpenPtNames()
    Workbooks.Open filename:="C:\Users\nunterseher.JCC\Documents\ZZ Daily other clinics\Clifty Patient Names.xlsx"
    ActiveWindow.WindowState = xlMinimized
End Sub

Why does this happen? What can I do to force this macro to run regardless of what workbooks are open?

Thanks,
Nate Unterseher
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
With your example files, try this:
Open excel
create new workbook
Now try to open your example workbook. In my case, the file opens, but the macro doesn't run.
 
Upvote 0
With your example files, try this:
Open excel
create new workbook
Now try to open your example workbook. In my case, the file opens, but the macro doesn't run.


Opening both from the open file icon in excel and opening the file directly from my desktop gives the same result... the macro's run
 
Upvote 0
That is what is so weird. These are not new macros. They have run beautifully for me for months with no problems. Within the last week, though, we did some Microsoft updates (I think only windows updates, not office 365). Since then, though, we have had these issues. As a workaround, the sole purpose for one of these macros is to update external links. I have had trouble getting them to work accurately through other methods so I just use VBA workbook_open to open the external workbook, allow excel to update the links, then close the external workbook again. Since this is not working now, do you have any recommendations for a workaround?
 
Upvote 0
I fixed this issue on my Excel. The macro would not work on open if any sheet in the workbooks was saved in Page Break Preview! As soon as I switched this back to normal view everything started working again. Good Luck!
 
Upvote 0
I fixed this issue on my Excel. The macro would not work on open if any sheet in the workbooks was saved in Page Break Preview! As soon as I switched this back to normal view everything started working again. Good Luck!

Happy you got a solution (I must admit I didn't even think about you could be in Page break preview mode - should have though so noted for future reference) :)
 
Upvote 0

Forum statistics

Threads
1,214,624
Messages
6,120,591
Members
448,973
Latest member
ksonnia

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