Saving and closing file without warnings

cbrf23

Board Regular
Joined
Jun 20, 2011
Messages
241
Can anyone tell me the best way to do suppress all warnings when saving a file programatically?
I'd like to suppress all warning dialogs.
I've set "application.displayalerts" to false, but I've got a dialog that still pops up which halts code execution.

The nature of this program is that it will update ALL the excel files on our server, so it needs to run when nobody else is on the server as it creates a lot of traffic opening and saving files.
Since there is nobody there to click "ok" when the dialog pops-up, the program never finishes :(

Here is the procedure that updates the files and saves the changes.
Interestingly, I found that just using the close method with "save changes" turned on wasn't working - it wasn't saving the changes. So I found I had to force it to save using the save method.
(the application.displayalerts setting is set in the calling procedure)
Code:
Private Function UpdateLinks(strPATH As String) As Boolean
    Dim lnkX    As Excel.Hyperlink
    Dim wshX    As Excel.Worksheet
    Dim wbkX    As Excel.Workbook
    Dim lngH    As Long
    
    UpdateLinks = False
    Application.StatusBar = "Updating file: " & strPATH & "..."
    On Error Resume Next
    Set wbkX = Excel.Application.Workbooks.Open(strPATH, 3, False, , , , True, , , , False, , False, True, xlNormalLoad)
    On Error GoTo 0
    
        If Not wbkX Is Nothing Then
                For Each wshX In wbkX.Worksheets
                    lngH = 0
                    lngH = wshX.Hyperlinks.Count
                        If lngH > 0 Then
                            UpdateLinks = True
                                For Each lnkX In wshX.Hyperlinks
                                    lnkX.Address = Replace(lnkX.Address, "\\oldserver\oldshare\", "\\newserver\newshare\")
                                Next lnkX
                        End If
                    wshX.Cells.Replace What:="\\oldserver\oldshare\", Replacement:="\\newserver\newshare\", MatchCase:=False, lookat:=xlPart
                Next
            wbkX.Save
            wbkX.Close
            UpdateLinks = True
        End If
    
    
End Function
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Displayalerts=false is working to suppress this dialog.
I must have someone skipped that line or changed it in the immediate window when I was originally testing as I just stepped through it again and it's working as intended.
Mods can feel free to delete this question or leave it if you see any value to it.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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