We use Titus for classification. I can save a macro in a local workbook, but I can't save anything to my universal PERSONAL.XLSB workbook. The Titus pop up won't go away no matter what options I choose.
The apparent cause is that Titus is trying to save to the wrong place, as shown in the picture below. Is there any fix for this other than disabling Titus? I'm on Win10, using Titus ClassificationSuite 4.5 HF3, Excel 2013. This exact macro saved to my personal.xlsb before my Win10 upgrade. (And by upgrade, I mean I got a new box with a fresh install)
You may want to use EnableEvents=False before saving and then EnableEvents = True.
The Idea is to disable the events so the popup is supressed and then save the file. Once the save operation is done we'd want to enable the events.
Titus is a Com Addin and usually this is visible on the
Depending upon what you select the CustomDocumentProperties are set. You can find this by clicking File-->Info-->Adavnced Properties as shown here
Now this is how you'd add customProperties programatically
Application.EnableEvents = False
With ActiveWorkbook.CustomDocumentProperties
.Add "CompanyClassification", False, msoPropertyTypeString, "Company-Public"
.Add "CompanyClassification", False, msoPropertyTypeString, "Company-Internal"
.Add "CompanyClassification", False, msoPropertyTypeString, "Company-Confidential"
.Add "CompanyClassification", False, msoPropertyTypeString, "Company-Secret"
End With
'Do the Save Operation here. Also if your company wants to Comply with EU GDPR (European General Data Protection Regulatory) then add the appropriate footer (Internal/Public/....)
Application.EnableEvents = True
I hope this should give you an idea on how to go forward.
I've found that if you edit the Personal.xlsb Workbook, and use the BeforeClose method such that:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.EnableEvents = False
End Sub
Then call the BeforeClose method to re-enable:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.EnableEvents = True
End Sub
Related
I'm sending an Excel workbook to users where I need automatic calculation to be always activated.
The problem is that I can't prevent users to put on manual calculation once they have the file.
The idea I had was to put on automatic calculation each time the user click somewhere in the workbook.
I tried to solve the problem with VBA and a workbook_activate macro :
Private Sub Workbook_Activate()
Application.Calculation = xlAutomatic
End Sub
It worked a time but now it seems that it doesn't work anymore.
Do you know what I can do to solve my problem ?
Foxfire's comments are perfectly valid. This should be approached as a training issue, rather than a technical change. However, there's nothing wrong with trying to do both to increase security. You could even alter the code to detect when a user has switched off autocalc and warn them this is against best practise.
The idea was to put on automatic calculation each time the user click somewhere in the workbook. But I don't know if this is possible...
You could use the Worksheet_SelectionChange event and that would give you exactly that. However, you'd have to put this in each of the worksheets.
A slightly better approach might be to only run when a change is made - after all, only a change should require a recalc. This can be done at a Workbook level like so:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.Calculation = xlCalculationAutomatic
End Sub
An alternative version - with a warning:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Application.Calculation <> xlCalculationAutomatic Then
Application.Calculation = xlCalculationAutomatic
MsgBox "Please do not disable automatic calculation blah blah blah.."
End If
End Sub
I am using power query to combine several tables together and output some info to another table, all within the same workbook.
I would like to ensure the output table is always up-to-date when the file is saved and don't want to depend on ppl using the 'Refresh All' button. Ideally I would have the queries update when the file is being saved.
For each query I have disabled the 'Enable background refresh' option in the query properties. I then have added the following vba code to ThisWorkbook:
Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ThisWorkbook.RefreshAll
End Sub
This does cause the queries to be updated before the file is saved. However if a user clicks on the save button (causing the queries to update & file saved), and then closes the file they are prompted to save the file again as if something has been edited... I have tried adding a wait command to the BeforeSave method after the refresh however the same behaviour occurs. We could of course just save it again or close without saving (since it was saved when we first hit the save button) however both are not ideal (file is on a network drive, so even though it is only a couple MB it takes several seconds to save, and not a fan of closing without saving).
Any tips for stopping Excel from asking us to save a workbook that we just saved?
Edit
From comments and suggested answers it seems that BeforeSave can be inconsistent. I did want to allow users to be able to close the workbook without saving so wanted to avoid using BeforeClose(for example a user made large changes to the workbook and wanted to undo everything). By manually setting the workbook saved state to true in Aftersave seems to have resolved the issue; atleast in my testing so far (even though it should already be true since it just saved?).
Option Explicit
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
If Success Then
ThisWorkbook.Saved = True
End If
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ThisWorkbook.RefreshAll
End Sub
Workbook.RefreshAll
It seems like the BeforeSave isn't always working as expected so your feedback is most welcome.
Option Explicit
Private DoNotBeforeSave As Boolean
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Me
If Not .Saved Then
.RefreshAll
DoNotBeforeSave = True
.Save
Debug.Print "Just refreshed and saved via 'BeforeClose'. Closing!"
Else
Debug.Print "No action taken via 'BeforeClose'. Closing!"
End If
End With
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Not DoNotBeforeSave Then
With Me
If Not .Saved Then
.RefreshAll
Debug.Print "Just refreshed and saved via 'BeforeSave'!"
Else
Cancel = True
Debug.Print "No action taken via 'BeforeSave'!"
End If
End With
End If
End Sub
I could not find a simple answer to this question, which I thought was odd. I was making changes to an Add-in I wrote and I was pressing the save button ever so often in the excel VBA editor. When I came back to make some more changes I found that all my changes over the last few days are gone. Is there any hope of recovering my work? More importantly, if I am making changes what is a better way of saving the project. I usually work out of my add on and only save a new copy when I need to send it out to a teammate.
I remember having this bad surprise at some point, but then I started to look closely at the save button before clicking and I noticed that VBA is telling you which workbook will be saved if you click on the floppy disk.
The reason why it is important to have a look at this is because the file that will be saved depends on what is currently selected in the Project Explorer and not what is currently visible in the VBA Code Editor Window.
You can also make sure that your add-in is properly saved by selecting one of its elements and running the following command in the Immediate Window (which should replicate exactly what the VBE save button does):
Thisworkbook.Save
Finally, unlike for other types of workbooks, Excel won't tell you when you close the application without saving changes to an add-in. For that reason, you can take extra precautions by adding the following code to the object Thisworkbook of your add-in:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If ThisWorkbook.Saved = False Then
Dim strMsg As String
' Specify the message to display.
strMsg = "Want to save your changes to '" & ThisWorkbook.Name & "'?"
Dim Decision As Boolean, ireply As Variant
ireply = MsgBox(prompt:=strMsg, Buttons:=vbYesNoCancel)
If ireply = vbYes Then
Decision = True
ElseIf ireply = vbNo Then
Decision = False
Else 'They cancelled (VbCancel)
Cancel = True
Exit Sub
End If
If Decision = True Then
ThisWorkbook.Save
End If
End If
End Sub
Which will prompt you with a message allowing you to save your add-in if it has an unsaved status when the Excel application is closing.
The following code, which is part of an Excel Add-In that I created, will create a file name of the current data extract that we have open.
Sub ExtractSave()
'
If InStr(LCase$(ActiveWorkbook.name), "extract") > 0 Then
Exit Sub
Else
Dim MyDir As String, fn As String
MyDir = CreateObject("WScript.Shell").SpecialFolders("MyDocuments") & "\Extract Files" ' change this to valid path
If Len(Dir(MyDir, vbDirectory)) = 0 Then MkDir MyDir
fn = MyDir & "\Extract - " & Format(Now, "mm-dd-yyyy hh_mm")
ActiveWorkbook.SaveAs Filename:=fn, FileFormat:=xlOpenXMLWorkbook
End If
End Sub
When I close the workbook, it does require a save to occur as changes will be made to the workbook. All of this works just fine. The issue is that the company has a .COM Add-In that is required to run on all documents. It labels the document footer with a specific security level identifier. While I do not need to bypass this, I would like to know if it is possible to write code that will replicate hitting enter when this box appears? There are two buttons, Yes and Cancel. The default button is Yes on the popup. I did try adding
Application.DisplayAlerts = False
If Me.Saved = False Then Me.Save
Application.DisplayAlerts = True
into the Workbook_BeforeClose private Sub, but the op still appeared. Also, if I am correct, this bit of code will not work for the Saved workbook because this is running from within the Add-In.
I have not been able to find any equivalent information for this particular issue, so any help would be appreciated. Also, I do not know what other information would be useful in your assistance to finding a solution, so please ask and do not down vote because I missed something.
Order of events:
Import data into new workbook
Run ExtractSave routine
See the .COM addin popup (need to have YES button pressed, YES is
the default button)
User performs duties on the workbook
Click on close
prompted to Save the changes to the workbook (again, default is YES,
need this "clicked")
See the .COM addin popup again(need to have YES button pressed, YES
is the default button)
What VBA code is available to automatically click on the YES buttons for the .COM add-in while saving the workbook?
From comments:
Adding Application.SendKeys ("~") before this line ActiveWorkbook.SaveAs Filename:=fn, FileFormat:=xlOpenXMLWorkbook worked when the first save event (#2 from the list in the OP) occurred.
And For #7 .COM addin popup, adding Application.SendKeys ("~") in Workbook_BeforeSave event didn't help (I hope someone can help us to fix it):
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
SendKeys "~"
End Sub
I have a workbook that I would like to open and not have it ask to update links, (exact message is :
"This workbook contains links to other data sources. If you update the links, Excel will attempt to retrieve the latest data. If you odon't update the links, Excel will use the previous information. Note that data links can be used to access and share confidential information without your permission and possibly perform other harmful acts. Do not update the links if you do not trust the source of this workbook." )
What I would like to do is open the workbook by clicking on the file in Internet Explorer and have the links update but not ask for the user to click the button to update.
I have tried the following code in the Open Event for the work book with not success:
Private Sub Workbook_Open()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
End Sub
I have also tried the following lines of code in the above Sub:
ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.FullName, Type:=xlExcelLinks
Application.ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.FullName, Type:=xlExcelLinks
Application.ActiveWorkbook.UpdateLink
Workbooks.Open ActiveWorkbook, UpdateLinks:=True
ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources, Type:=xlExcelLinks
The version of MS Excel 2010 and saving to an .xls file for sake of those with legacy versions.
Your help would be very appreciated. Thank you in advance for all your help.
Respectfully,
Robert
Just in case this might help anyone in the future the following is what I did:
Private Sub Workbook_Activate()
Application.AskToUpdateLinks = False
End Sub
This prevented the Update Links message box from appearing when the file is opened.
Robert
Just to add to Robert's (#user2320821) answer -
I had to modify the code to:
Sub Workbook_Open()
Application.DisplayAlerts = False
Application.AskToUpdateLinks = False
Application.DisplayAlerts = True
End Sub
The key differences being that
1) It's a Workbook_Open sub instead of a Workbook_Activate sub. The Activate sub was not suppressing the Update Link request.
2) I had to throw in a DisplayAlerts flag toggle to suppress a second warning about the links not being updated, even after the first Update Link request was suppressed.
In case it wasn't obvious in Robert's answer, this sub worked when I put it in the ThisWorkbook object.
I'm using this code in my vba .xlm file..
Private Sub Workbook_Open()
ThisWorkbook.UpdateLinks = xlUpdateLinksNever
End Sub
M Office2013