Excel file corrupts after adding VBA but only on a "save as" when changing the file name

luvlynn1

New Member
Joined
Sep 6, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have a file with four buttons to refresh specific queries in PQ in a certain order after certain things are accomplished each day. My original file works just fine. However when I save a copy with a new name, keeps the original name with the date on the end, the new file gives me an error saying the file is corrupt and to recover it.

This is what I see when the repair happens

Removed Part: /xl/vbaProject.bin part. (Visual Basic for Applications (VBA))

Repaired Records: Cell information from /xl/worksheets/sheet1.xml part

Repaired Records: Cell information from /xl/worksheets/sheet2.xml part

Repaired Records: Cell information from /xl/worksheets/sheet5.xml part

Repaired Records: Cell information from /xl/worksheets/sheet6.xml part

Repaired Records: Cell information from /xl/worksheets/sheet9.xml part

Repaired Records: Cell information from /xl/worksheets/sheet10.xml part


Below is an example of the code. Three buttons are exactly like this. the following code is the one that is slightly different.



Private Sub RefreshALL_Click()

Application.ScreenUpdating = False

ThisWorkbook.Connections("Query - Clerk Cheat Sheet").Refresh

ThisWorkbook.Connections("Query - Freight Report").Refresh

ThisWorkbook.Connections("Query - qry_bol_hdr_cans").Refresh

Application.ScreenUpdating = True

End Sub



Private Sub RefreshPSG_Click()

Application.ScreenUpdating = False

Range("B2") = Date

Range("tblRoutes[LOAD]").Select

Selection.ClearContents

Range("AD7:AF32").Select

Selection.ClearContents

Range("AD35:AF36").Select

Selection.ClearContents

Range("AF34").Select

Selection.ClearContents

ThisWorkbook.Connections("Query - qryPSG_detail").Refresh

ThisWorkbook.Connections("Query - tblRTKData").Refresh

Application.ScreenUpdating = True

End Sub

Currently I can save my historical file as an XLSX but I would like to be able to just save it to keep it simple for anyone coming in after me.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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