DisplayAlerts for PPT links not working - vba

I'm running a VBA macro in PowerPoint, in which I open another PowerPoint document with several links in it.
I don't want the pop-up with the question to update these links to appear. So I included Application.DisplayAlerts = False. However this doesn't work: My macro still stops and shows the dialog, and I need to press Enter to be able to continue.
How do I fix this?
Application.DisplayAlerts = False
Presentations.Open FileName:=stdRapport, ReadOnly:=msoFalse
ActivePresentation.UpdateLinks

.DisplayAlerts has never done much in PPT, unlike Excel et al.
You can theoretically disable hyperlink warnings via the registry. I've got a page here that gives the general outline and includes links to the relevant pages on MS for various Office versions:
Security warning message when clicking a hyperlink: "files might harm your computer"
http://www.pptfaq.com/FAQ00587_Security_warning_message_when_clicking_a_hyperlink-_-files_might_harm_your_computer-.htm
I don't think there's any way of disabling hyperlink warnings on someone else's computer.

Related

How Do i turn off tracked changes using macros?

I have been trying to create a macro that will automatically run when I open a new word document that will verify that tracked changes are turned off. For some reason, whenever I run a macro that opens a new word document that is a .dotm file that contains a form, it turns on tracked changes and I have not told it to do so.
I have tried various different ways of fixing this issue.
Before I close the User form that has been opened when I opened the new file, I add this line
ActiveDocument.TrackRevisions = False
I also tried with an if statement
if(ActiveDocument.TrackRevisions) then
ActiveDocument.TrackRevisions = False
end if
I also tried doing it so that it was not even involved in the user form at all but the document itself by inserting it in the "ThisDocument" section under the "Microsoft Word Objects" File. Here is what is located there.
Private Sub Document_New()
UserFormInfo.Show
'ActiveDocument.Bookmarks("cursor").Select
ActiveDocument.TrackRevisions = False
ActiveDocument.Save
End Sub
I expect to have this turn off tracked changes, however, this does not occur. Any help is appreciated.
What ended up working for me is I had to remake my template. I had to export my user form so that it was fully removed from all my word files and then remake the template, after that, I had no problem with tracked changes turning on when I ran my macro to open this template. I believe it was a setting I must have had turned on when I had made my template.

Getting a .xlsm file to not execute code when being opened with VBA

I have a macro in Excel. Part of that macro opens up other workbooks using Workbooks.Open(Filepath).
Some of the workbooks I'm opening have (badly done) VBA code inside of them, that try to then calculate a UDF and fail horribly.
Without resorting to an On Error Resume Next or an On Error GoTo, how do I say "Open this file, DO NOT RUN ANY CODE".
Trying to avoid letting the code execute in the first place due to possible security concerns. I feel comfortable enough opening these files, and there's a decent chance that they're not going to be compromised, but breaches can happen, and why have a hole when I don't need one? I also don't want error messages interrupting my code executing.
Searching the web just shows me shift+open opens the file without executing code, which is not at all what I'm looking to do. I'm looking for the equivalent VBA method.
AutomationSecurity is likely what you want:
https://learn.microsoft.com/en-us/office/vba/api/Excel.Application.AutomationSecurity
MsoAutomationSecurity can be one of these MsoAutomationSecurity
constants.
msoAutomationSecurityByUI . Uses the security setting specified in the
Security dialog box.
msoAutomationSecurityForceDisable . Disables all
macros in all files opened programmatically without showing any
security alerts. Note This setting does not disable Microsoft Excel
4.0 macros. If a file that contains Microsoft Excel 4.0 macros is opened programmatically, the user will be prompted to decide whether
or not to open the file.
msoAutomationSecurityLow . Enables all
macros. This is the default value when the application is started.
You can disable the macros for newly opened files, open the workbook, and then re-enable the macros:
Private Sub OpenWorkBookMacroDisabled(wbPath As String)
Application.AutomationSecurity = msoAutomationSecurityForceDisable
Workbooks.Open (wbPath)
Application.AutomationSecurity = msoAutomationSecurityByUI
End Sub

MS Office - ActiveX Buttons switching places

There are several instances of this problem, but this one is predominant. This is in relation to updates (our most notable problem child being KB2726958). We have a Leave Spreadsheet that looks like this:
Leave Spreadsheet example
By pressing the grey Leave button, you end up here:
Leave Word doc
All the programming for these is written in VBA (i've never worked with VBA before, I can understand it to a degree).
Now, the issue is that using the ActiveX button in the 'Leave Spreadsheet example' causes the 2 buttons 'Send by Email' and 'Save' to switch functions; Send by email attempts to save and save opens up Outlook and creates the email message.
Both functions have completely retained functionality, just on the wrong buttons.
The thing I find weird is that a hyperlink to the very same file works; the buttons aren't switched and have full functionality. The only hint that I have towards resolution is that when using a hyperlink, it's directly opening the file. When using the ActiveX button, it seems to be creating a new file based off the file it's linking to. For example, the hyperlink directly opens C:\Report.dotm but the ActiveX button opens Document1.doc with a template based on Report.dotm.
I'm considering that maybe the activeX button is opening up Word with an incorrect extension? But i'm not sure how to figure this out (code below shows that the linked file on the activeX control is a .dotm).
What further throws a spanner into the mix is that it only affects some computers... Considering on-site we all use the same type of PC with the same image... :(
My question is, does anyone know why they may be swapping? They're located on the same network drive albeit different directories. They require the same permissions to access. The code for the buttons is as follows:
Excel Button:
Private Sub CommandButton1_Click()
' This button links the excel spreadsheet to the word doc
Dim wrdApp As Object
Dim wrdDoc As Object
Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add("\\networkdrive\directories\Request for Leave.dotm")
End Sub
Word buttons 1 and 2:
Private Sub cmdSend_Click()
' This is the code for the button 'Send by Email'
MsgBox "Send the following email to your Team Leader/Line Manager", vbInformation
SendDocumentAsAttachment "", "IPL Request for Leave"
End Sub
Private Sub cmdSave_Click()
' This is the code for 'Save'
modSend.SaveLeaveForm
End Sub
Please Note: The comments above are not in the code in VBA, i've written them in myself in this question to provide clarity.
Troubleshooting that i've done:
Removing all .exd files
Running the MS Hotfix (removes all .exd files in a GUI)
The next step would be to try running all 6 patches related to fixing ActiveX controls with the particular patches we've done to see if that fixes the problem. The reason I haven't done this yet is because of ITIL (Change management) although I may try testing this later today.
What is the outcome i'm after?
Ideally, I want to understand what is causing these buttons to, from what it looks like, swap their functions. I have different scenarios of button swaps, some of which are remedied by removing the .exd files, and some that aren't.
By understanding what is happening, I hope that I can apply the knowledge to the other scenarios (same problem, different coding).
Then, I'll be able to document my findings so that when we perform the next round of patching that is known to break ActiveX controls, my organization will know how to deal with it.
So the patch mentioned below has fixed this issue. There's still some other issues that I need to test this patch against, but I definitely should have started there. Lesson learnt.
From my work email:
I’ve just tried using the patch related to the ActiveX controls breaking, KB2920754. I’ve used it on two PC’s here in the training room; both had different issues:
- The first one had buttons that had switched around (save attempted to email, email attempted to save)
- The second one couldn’t use the buttons at all.
This patch cured both w/o requiring a restart or logging out and back in. I didn’t remove any .exd files, either.
It does state, however:
“Important For this fix to be fully effective, you also have to apply the other patches for Office 2013 that are listed in the "Resolution" section of the following Microsoft Knowledge Base article”
There are 6 in total.
Patches:
1. KB2920754 – (the one I’ve used successfully)
2. KB2956145
3. KB2956163
4. KB2965206
5. KB2956176
6. KB2956155

VBA Password Prompt shows on Exit from Excel

I have been experiencing an issue where the VBA Password Prompt appears when exiting Excel for workbooks that have a locked VBA project.
For me it is happening on a Win10 / Excel2013 and Win10 / Excel2016 environment. I have searched for and tried a number of possible solutions. See the attached workbook and a step recorder that shows this happening for one of the tests. One interesting difference for the tests that are included to the workbook is in the case where a "pop-up" form is displayed, when closing the VBA password prompt is shown 5 times instead of 3 times on a standard exit from the workbook for the other tests.
Sample Workbook - https://sites.google.com/a/xlautomation.com.au/website/free-downloads/TestVBAPassword%20v2%20Share.xlsm?attredirects=0&d=1
Password to see the code in this workbook...."password"
Step Recorder showing the issue - https://sites.google.com/a/xlautomation.com.au/website/free-downloads/VBA%20Password%20Prompt%20Example.zip?attredirects=0&d=1
I can see from other posts that this problem has appeared over the years and some have resolved it with removing Add-In references, Closing Excel in a certain way none of these are working in my case. It is not a viable option to unprotect the VBA project as the workbooks are shared with others and allowing access to the code would present support issues.
If anyone has further suggestions to resolve this issue please share those back.
I have also include a demo of the issue in action below...
Could it be you have Dropbox installed on your system. A weird pointer to it solved my solution (short of making the Excel sheet into an xlam add-in) in no longer asking for the password:
right click on Dropbox symbol in system tray
Select the gear symbol (settings) at the right top
Select "Preferences"
In its "General"tab set "Show Dropbox Badge" to "Never show".
Click OK
That's it. How that affects Excel I don't know.

Excel changes Link to Add-in

I need to link up an .xls (must not have macros) to a macro on our network. I thought I had found a good solution, which uses a shape to link up to a macro that is set an add-in in Excel. This method worked well for over a year, but now things are starting to act REALLY ODD. Excel keeps changing my links from the network to the local drive!
Basically, at my computer I run code that creates a button and sets the .OnAction value to 'SPC_BUTTONS.xlam!EXPORTSPC' which excel sometimes updates to 'G:\NetworkLocation\SPC_BUTTONS.xlam!EXPORTSPC' (sometimes it leaves it alone). I linked up the add-in to run from the network (and don't copy it locally) so this is a correct address for it. However when I move the file from my computer, to the network and on to the final computer, the link will change to 'C:\NetworkLocation\SPC_BUTTONS.xlam!EXPORTSPC'. The file's links work until the point it lands on the local computer.
'Check if SPC Button already exists
Dim exportButton As Shape
On Error Resume Next
Set exportButton = InspectionWS.Shapes("SPC Button")
On Error GoTo 0
If Not exportButton Is Nothing Then
'Delete the old button
InspectionWS.Shapes("SPC Button").Delete
End If
'Create "SPC Button"
InspectionWS.Shapes.AddShape(msoShapeRectangle, 770, 600, 160, 36).Name = "SPC Button"
Set exportButton = InspectionWS.Shapes("SPC Button")
With exportButton
.ShapeStyle = msoShapeStylePreset34
.TextFrame2.TextRange.Characters.Text = "Export SPC Data"
.TextFrame2.TextRange.Font.Size = 20
.TextFrame2.WordArtformat = msoTextEffect8
.OnAction = "EXPORTSPC"
End With
The first time I saw this problem was when I had changed the add-in. I had made another macro in that file called EXPORTSPC2, and had swapped names with original when it was time to go live. That's when all of the links became broken. I swapped back the names and decided to just swap the code, in case position mattered. Still didn't help with the linking.
I looped the original macro that set up the buttons on every file again, but that failed to rectify the problem. Several hours later, after trying a lot of options I found setting .OnAction to just 'EXPORTSPC' did again get some files to link up again, but ONLY if I did it on the local computer. I had tried the full address, a local address (and moving the add-in location), and SPC_BUTTONS.xlam!EXPORTSPC and of those still ended up with 'C:/Networklocation.xlam!EXPORTSPC'... even when set on the local computer.
The problem is, yesterday, it happened again when someone had replaced the updated files with another set of files he had been modifying on the network. This time around I wasn't surprised to see that they didn't link up (although disappointed), but was surprised that the my code looping the update to EXPORTSPC failed to 'take' for all of the files on the second computer. Only a handful of them would actually change to EXPORTSPC, and I ended up having to assign the link locally on the final computer(s), by hand, for each of the 45 .xls files.
Really, I can't keep doing any of this local repairing, as it creates machine downtime.
So my questions! Is there a better way to do what I'm trying to accomplish (.xls to add-in)? Any idea as to why is moving these files causing excel to change the link, forcing me to set them up locally? Why does it suddenly not accept anything but EXPORTSPC as the link name? Does excel save some sort of ID for macros/add-in/buttons I'm unaware of I'm accidently breaking?
Really, Any sort of insight will help. Thanks!
EDIT:
I did find an error in my looping code, which effected the issue I had on the second computer. It was looping through each workbook fine and saving... but I didn't activate the workbook before running the code, which was pretty important (DOH!). This only resolves the problem I ran into yesterday where I had to edit by hand.
However, digging a little deeper, I do feel like I have a better understanding. I used the code below to determine if what I see in 'Assign Macro' matches the stored .OnAction value, which it does not. Testing on my computer this code:
exportButton.OnAction = "'G:\NetworkLocation\SPC_BUTTONS.xlam!'EXPORTSPC"
would cause the 'Assign Macro' to change to 'EXPORTSPC', even though debugging
debug.print exportButton.OnAction
still displayed the original OnAction value. When I moved the file to the shop floor computer, 'assign macro' would display 'G:\NetworkLocation\SPC_BUTTONS.xlam!'EXPORTSPC until I clicked it, and then it would switch to EXPORTSPC.
So it seems Excel does keep track of where the macro is located once it detects the correct location. I swapped the macros around and it seemed to have broke the connection. My guess is excel then modifies the location to the C:\ once it's internal link is broken. If anyone has any elaboration/verification of this, I'd love to hear it.
I do recall having the add-in button becoming unchecked randomly, which may have been playing into why links kept breaking and reverting to the c:\ while I was debugging what would work. I'm not sure what was causing that either. But using the all forms of exporting seemed to work today. I'm still not convinced that I won't see it again though, since I don't fully understand what was the catalyst of unchecked boxes and swapped links.
If Not exportButton Is Nothing Then
With exportButton
.OnAction = "'SPC_BUTTONS.xlam'!EXPORTSPC"
'.OnAction = "EXPORTSPC"
'.OnAction = "'G:\NetworkLocation\SPC_BUTTONS.xlam'!EXPORTSPC"
End With
Debug.Print exportButton.OnAction
End If
So parts of the process still seem fuzzy, but at least now I know how to better track what I'm seeing.
Try this -- qualify the Add-In filename:
.OnAction = "SPC_BUTTONS.xlam!EXPORTSPC"
I have tested this with an XLAM on a network drive, and an XLS file on my desktop. I have copied the XLS file to a network location, and it still works. I have also done a SaveAs to put the XLS file on yet another network drive, and the action continues to work.
This of course requires that the user's instance of Excel has the Add-In enabled.
Alternatively, try enclosing the path & filename in single-quotes:
.OnAction = "'G:\NetworkLocation\SPC_BUTTONS.xlam'!EXPORTSPC"
This method seems to be preserving the OnAction absolute path.