Save workbook when updating exchange rates

CV899000

Board Regular
Joined
Feb 11, 2016
Messages
98
Hello,

I have, with help of this forum, gotten my workbook to close without asking to save.

I have done that with this code;
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
  Saved = True
End Sub

Now, the problem is, that this code disables anybody from saving any changes (and that is good, most of the time).

However, I have 1 sheet and two cells in another sheet that I would like to be able to save, and that revolves around my exchange rates.
I have a command button that I can press to update my exchange rates in a sheet called "exchange rates" and then I have two cells in a sheet called "Prices" which contains the date and time of the last update and who updated it.

But, the code that disables the save function, also does so that I cannot save the new exchange rates and information in "Prices" when I have updated the rates.

Can I put a code into my command button sub, that saves the document when the exchange rates has been updated?

Here is the code for the command button that updates my rates:

Code:
Sub Update_rates()
Application.ScreenUpdating = False
Sheets("Exchange rates").Visible = True
' Update_rates Macro
    If MsgBox("Internet connection needed to update exchange rates. Update now?", _
    vbYesNo) = vbNo Then
    Sheets("Exchange rates").Visible = xlVeryHidden
    Application.ScreenUpdating = True
    Exit Sub
    End If
    Sheets("Exchange rates").Select
    Range("A1").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
    Sheets("Prices").Select
Sheets("Exchange rates").Visible = xlVeryHidden
Application.ScreenUpdating = True
    MsgBox "Exchange rates has been updated from [URL="http://www.x-rates.com/"]Exchange Rates - X-Rates[/URL]"
Range("K7") = Now
Set objAD = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objAD.UserName)
strDisplayName = objUser.DisplayName
Range("K5").Value = (strDisplayName)
End Sub
 
Last edited:

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.
Could you not just use:

Code:
ThisWorkbook.Save

rather than

Code:
Saved = True
 
Upvote 0
I could have, but the problem is that I have another code that unhides three sheets when I open the workbook.
If I save the workbook with these sheets visible, then they won't be hidden next time.
But I kind of used your advice, I did this to my update rates code:

Code:
Sub Update_rates()
Application.ScreenUpdating = False
Sheets("Exchange rates").Visible = True
' Update_rates Macro
    If MsgBox("Internet connection needed to update exchange rates. Update now?", _
    vbYesNo) = vbNo Then
    Sheets("Exchange rates").Visible = xlVeryHidden
    Application.ScreenUpdating = True
    Exit Sub
    End If
    Sheets("Exchange rates").Select
    Range("A1").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
    Sheets("Prices").Select
Sheets("Exchange rates").Visible = xlVeryHidden
Application.ScreenUpdating = True
    MsgBox "Exchange rates has been updated from [URL="http://www.x-rates.com/"]Exchange Rates - X-Rates[/URL]"
Range("K7") = Now
Set objAD = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objAD.UserName)
strDisplayName = objUser.DisplayName
Range("K5").Value = (strDisplayName)
Application.ScreenUpdating = False
    Sheets("Macros disabled").Visible = True
    Sheets("Information").Visible = xlVeryHidden
    Sheets("Prices").Visible = xlVeryHidden
    Sheets("Copied Prices").Visible = xlVeryHidden
ThisWorkbook.Save
    Sheets("Information").Visible = True
    Sheets("Prices").Visible = True
    Sheets("Copied Prices").Visible = True
    Sheets("Macros disabled").Visible = xlVeryHidden
Application.ScreenUpdating = True
End Sub

And kept my beforeclose code the same.
 
Last edited:
Upvote 0
Or just place ThisWorkbook.Save as suggested by Steve at the very end of the Update_rates routine but be aware that as per your previous thread you may also have to hide the worksheets that are supposed to be hidden and make the "macro disabled" sheet as the welcoming sheet before saving the workbook.
 
Upvote 0
Or just place ThisWorkbook.Save as suggested by Steve at the very end of the Update_rates routine but be aware that as per your previous thread you may also have to hide the worksheets that are supposed to be hidden and make the "macro disabled" sheet as the welcoming sheet before saving the workbook.

That I exactly what I have done :biggrin:
 
Upvote 0

Forum statistics

Threads
1,221,444
Messages
6,159,912
Members
451,601
Latest member
terrynelson55

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