NWalsh3000
New Member
- Joined
- Aug 5, 2015
- Messages
- 10
Ok, so I have made my self pretty decent at figuring out how to do things in excel but I have no formal training so sometimes I miss things that are right in front of me. I have written this macro to refresh my whole workbook and then close the workbook. I have some hidden tabs as well as lock work sheets so there is a little extra vba in it. My problem is the macro fails when i attach it to a shape (button) or just run it. However it works perfectly when I use the step through function. Does anybody see my mistake? Here are the details THANK YOU!
OK so after I run I get a popup box that says "This will cancel a pending data refresh, Continue?" If I click "OK" It finishes the macro but cancels the refresh and close I need.
However like I said, If i step through the macro it works like a charm.
Here is my Macro:
Sub Refresh_Close()
'
' Refresh_Close Macro
'
'Screen Off
Application.ScreenUpdating = False
'Show Tabs
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws
'Unprotect
Call UnProtect_All
'Refresh All & Pause 10 Secs
ActiveWorkbook.RefreshAll
'Application.Wait (Now + TimeValue("00:00:10"))
'Protect
Call Protect_All
'Hide Tabs (ALL EXCEPT Admin)
Sheets(Array("Inventory (Beer)", "Inventory (Liquor)", "Inventory (Wine)", "Order (Beer)", _
"Order (Liquor)", "Order (Wine)", "Mt Beer Pricing", "Mt Liq Pricing", "New Product" _
, "DD & INFO", "Totals", "Invoices", "Spill & Transfer", "Admin", "Cost (Beer)", "Cost (Liquor)", "Cost (Wine)", "Mt Wine Pricing")).Select
ActiveWindow.SelectedSheets.Visible = False
'Save Workbook * Pause 5 Seconds
ActiveWorkbook.Save
'Application.Wait (Now + TimeValue("00:00:05"))
'Screen On
Application.ScreenUpdating = True
'Close Workbook
Application.Quit
'
End Sub
Thanks in advance for all your help!
Norm
OK so after I run I get a popup box that says "This will cancel a pending data refresh, Continue?" If I click "OK" It finishes the macro but cancels the refresh and close I need.
However like I said, If i step through the macro it works like a charm.
Here is my Macro:
Sub Refresh_Close()
'
' Refresh_Close Macro
'
'Screen Off
Application.ScreenUpdating = False
'Show Tabs
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws
'Unprotect
Call UnProtect_All
'Refresh All & Pause 10 Secs
ActiveWorkbook.RefreshAll
'Application.Wait (Now + TimeValue("00:00:10"))
'Protect
Call Protect_All
'Hide Tabs (ALL EXCEPT Admin)
Sheets(Array("Inventory (Beer)", "Inventory (Liquor)", "Inventory (Wine)", "Order (Beer)", _
"Order (Liquor)", "Order (Wine)", "Mt Beer Pricing", "Mt Liq Pricing", "New Product" _
, "DD & INFO", "Totals", "Invoices", "Spill & Transfer", "Admin", "Cost (Beer)", "Cost (Liquor)", "Cost (Wine)", "Mt Wine Pricing")).Select
ActiveWindow.SelectedSheets.Visible = False
'Save Workbook * Pause 5 Seconds
ActiveWorkbook.Save
'Application.Wait (Now + TimeValue("00:00:05"))
'Screen On
Application.ScreenUpdating = True
'Close Workbook
Application.Quit
'
End Sub
Thanks in advance for all your help!
Norm