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

.xlsm Export freezing up

Status
Not open for further replies.

supportsvc

Technical User
Jan 24, 2018
249
US
Hello,
I can't figure out why, but the script to refresh, save then export and save as a .xlsx from the .xlsm with multiple worksheets keeps freezing, I believe on processing the Export function.

This hasn't happened before so I am not sure why it started.

I compared the script with other workbooks that do the same and even copied and pasted and edited the worksheets names.

When I open the .xlsm without launching the code and RefreshAll, that all works. So I know it's not that part. When I select the export section, it worked but then when attempted again, it froze.

This is the only thing that's available as to the freezing up issue. Anyone know what it could be?

Code:
Problem signature:
  Problem Event Name:	BEX
  Application Name:	EXCEL.EXE
  Application Version:	16.0.10325.20118
  Application Timestamp:	5b68edfd
  Fault Module Name:	mso20win32client.dll
  Fault Module Version:	0.0.0.0
  Fault Module Timestamp:	5b523906
  Exception Offset:	001cc5e4
  Exception Code:	c0000409
  Exception Data:	00000000
  OS Version:	6.3.9600.2.0.0.272.7
  Locale ID:	1033
  Additional Information 1:	d8a0
  Additional Information 2:	d8a003d775674474d9dbe93763039399
  Additional Information 3:	2019
  Additional Information 4:	2019e8e39e89e6d242ffd268a36c7e98

Read our privacy statement online:
  [URL unfurl="true"]http://go.microsoft.com/fwlink/?linkid=280262[/URL]

If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt

Here's the script:
Code:
Private Sub Workbook_Open()
    Dim myPath As String
    
    Application.DisplayAlerts = False
    ThisWorkbook.RefreshAll
    DoEvents
    Application.DisplayAlerts = False
    ThisWorkbook.Save

    myPath = Application.ActiveWorkbook.Path
    Worksheets(Array("DailyOps", "Consolidated", "Bookings", "Shipped", "OpenOrders", "Backlog")).Copy
    ActiveWorkbook.SaveAs Filename:="C:\Users\Operations\DailysOps-" & Format(Date, "yyyy-mm-dd") & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    DoEvents
    Application.Quit
End Sub
 
Hi,

Put a Stop before the first executable line of code.

SAVE.

Then reopen and Step thru your code to determine exactly where it goes south.



Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
...and exactly what does this do for you?
Code:
'
    myPath = Application.ActiveWorkbook.Path
    Worksheets(Array("DailyOps", "Consolidated", "Bookings", "Shipped", "OpenOrders", "Backlog")).Copy

NOTHING! You never use either

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Thought it was To save the workbook for each worksheet in the workbook
 
Not so!

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
You are making a copy of a workbook that obviously has a macro in it and trying to save it as .xlsx that cannot have macros.

What do the two "DoEvents" statements do for you?
 
The script is derived from googling.
It worked until recently and there are over 12 workbooks using the same.

Only differences are:
1) the worksheet names
2) the file name of the workbook being saved as

I believe the problem is occuring at the export line of the script.
 
save it as .xlsx that cannot have macros"
I guess that's why there are rwo [tt]Application.DisplayAlerts = False[/tt] to eliminate any warning messages...


---- Andy

There is a great need for a sarcasm font.
 
Can't remember what the DoEvents fixed but there was an issue and adding that fixed it.

It appears to be at the Worksheets(Array("DailyOps", "Consolidated", "Bookings", "Shipped", "OpenOrders", "Backlog")).Copy line
removed that and it seems to be working.

That is strange, as mentioned, the other 11 workbooks has this line since not all worksheets are being "copied" and saved as a .xlsx file.
 
Maybe that’s a feature that I’m ignorant of. Never saw that before.

If that is indeed saving only the sheets in the saved array in other cases, then check that the names in the array are correct and that you have no leading/trailing spaces, for instance.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Interesting...
Just created a new Workbook with sheets "Andy", "Barb", and "Chad", provided some data in all 3 sheets, and executed:
[tt]
Worksheets(Array("Andy", "Chad")).Copy[/tt]

That created another Excel file with just 2 sheets: "Andy" and "Chad", ready to be saved.

Who knew...[ponder]


---- Andy

There is a great need for a sarcasm font.
 
Yes, doubled checked the spelling and such of the worksheets in the .copy line

Andrzejek, yes, when saving it as .xslx, need to remove the macro.
and yes, that's why the .copy is needed if there are worksheets not wanting to be saved
 
Yes, who knew! I learned something! 👍

I have no other suggestions in mind.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top