MS Word security notice when creating a Word object and Word is already running
I have a VB6 app that creates a Word object. (Windows 11 PC)
DIM MSWord as object
Set MSWord = CreateObject("word.application","localhost")
The app calls macros that exist in Word template Normal.dotm.
For years this app has worked flawlessly until this week where I now get a "Microsoft Word Security Notice". The security notice message box gives the following message:
"Microsoft Office has identified a potential security concern."
"Microsoft has blocked macros from running because the source of the file is untrusted."
"File Path: C:\Users\signu\AppData\Local\Microsoft\Windows\INetCache\Content.Word\~WRC0004.tmp"
I have discovered that this security notice only appears if a desktop instance of Word is already running. If Word isn't already running then my app works.
If the security notice window isn't closed with about 10 seconds, VB errors out with a the following error:
Error -2146959355
Server execution failed
I have also discovered that if Word is already running but Normal.dotm has no macros in it, then the security notice doesn't appear when I run my app. But of course my app can't work correctly without the macros.
I have the path to Normal.dotm set as a trusted location in Word's trust centre options.
Has anyone else suddenly got this Word security notice? Any ideas?
Re: MS Word security notice when creating a Word object and Word is already running
Does your application, or one of the user's documents, create the ~WRC0004.tmp in the Internet Cache folder?
What happens if you clear the files from that Internet Cache folder? DO you still get the message.
Microsoft assumes that any file from the Internet is untrustworthy when macros are involved. There is a flag on the file indicating that it came from the Internet. Note that this will be true even if the file did not actually come from the Internet, but has content copied and pasted from an Intranet web site or from any web browser content, even on the local file system.
Re: MS Word security notice when creating a Word object and Word is already running
This isn't an answer. But, if it were me, I'd move those macros into my VB6 program. Whatever you can do in a macro, you can also just directly do in VB6.
ADDED: Ohh, and they'll run a bit faster too because they'll be compiled rather than interpreted p-code (which is all the VBA has).
Re: MS Word security notice when creating a Word object and Word is already running
Quote:
Originally Posted by
jdc2000
Does your application, or one of the user's documents, create the ~WRC0004.tmp in the Internet Cache folder?
What happens if you clear the files from that Internet Cache folder? DO you still get the message.
Microsoft assumes that any file from the Internet is untrustworthy when macros are involved. There is a flag on the file indicating that it came from the Internet. Note that this will be true even if the file did not actually come from the Internet, but has content copied and pasted from an Intranet web site or from any web browser content, even on the local file system.
When the line 'Set MSWord = CreateObject("word.application","localhost")' is executed, the ~WRCxxxx.tmp file gets created and the Word Security Notice appears.
I cleared all the ~WRCxxxx.tmp files from the cache folder and the message still appears.
I forgot to mention this is a Windows 11 PC.
Re: MS Word security notice when creating a Word object and Word is already running
Quote:
Originally Posted by
Elroy
This isn't an answer. But, if it were me, I'd move those macros into my VB6 program. Whatever you can do in a macro, you can also just directly do in VB6.
ADDED: Ohh, and they'll run a bit faster too because they'll be compiled rather than interpreted p-code (which is all the VBA has).
Thanks. I didn't realise I could run the exact same macro code within my VB6 program. Off to Google to see how to do it........
*Update*
I've sussed out what to do.
Now in process of testing it out.
Thanks for the suggestion.
Re: MS Word security notice when creating a Word object and Word is already running
You can remove the flag that tells Windows it's a file from the internet.
ZoneStripper
Pretty simple code; with a reference to oleexp.tlb:
Code:
Public Sub RemoveFileSecurityZone(sFile As String)
Dim pZI As PersistentZoneIdentifier
Set pZI = New PersistentZoneIdentifier
pZI.Remove
Dim pIPF As IPersistFile
Set pIPF = pZI
pIPF.Save sFile, 1
Set pIPF = Nothing
Set pZI = Nothing
End Sub
If it's read-only you'd have to remove that attribute;
Code:
Private Declare Function GetFileAttributesW Lib "kernel32.dll" (ByVal lpFileName As Long) As Long
Private Declare Function SetFileAttributesW Lib "kernel32.dll" (ByVal lpFileName As Long, ByVal dwFileAttributes As Long) As Long
Public Sub ClearReadOnly(sFile As String)
'Removes the read-only attribute
Dim lAtr As FILE_ATTRIBUTES
lAtr = GetFileAttributesW(StrPtr(sFile))
lAtr = lAtr And Not FILE_ATTRIBUTE_READONLY
Call SetFileAttributesW(StrPtr(sFile), lAtr)
End Sub
Re: MS Word security notice when creating a Word object and Word is already running
Quote:
Originally Posted by
nealb
Thanks. I didn't realise I could run the exact same macro code within my VB6 program.
A trick I've used very often is to use the Macro Recorder procedure in either Word or Excel, get it to do what I want, and then copy/paste/patch_up that code and put it into my VB6 program. It's a great way to get things going without spending hours in the MSDN sussing out all the VBA object model.
Also, when you do that (use the Macro Recorder), it puts all kinds of superfluous code into the macros, which I typically delete when I move that code over to VB6. But, so long as the main application object is patched up correctly, it doesn't hurt to leave it.
Also, just a comment on your original problem ... once all your code is in your VB6 project, you've completely circumvented the MS-Office security apparatus. And then you just have to worry about your VB6 program not having any code in it that looks like a virus. But once your EXE is cleared to run, you should be good to go, manipulating Word & Excel documents all you want.
Re: MS Word security notice when creating a Word object and Word is already running
Quote:
Originally Posted by
Elroy
A trick I've used very often is to use the Macro Recorder procedure in either Word or Excel, get it to do what I want, and then copy/paste/patch_up that code and put it into my VB6 program. It's a great way to get things going without spending hours in the MSDN sussing out all the VBA object model.
Ha ha, that brings back memories. I did just that to create my Normal.dotm macros many years ago.
I've transferred all my macros now into my VB6 programs and so far so good, they are working.
Now I hopefully won't have to worry about Microsoft with what seems to be constantly changing the goalposts with their macro security in Word.
Thanks for your help.
Re: MS Word security notice when creating a Word object and Word is already running
Glad you got it going. And another benefit ... now you don't have to install your Normal.dotm on each of your users' machines. Just install your VB6 program, and you should be good to go.