Am I doing something silly?

A

Andy

Hi,
I've just posted a similar Q below to do with word2000, but in the long run
I need to get this going with word2003.

Basically I get an error when programatically openning a word doc which
contains macros when DisplayAlerts are set to none (wdAlertsNone) and macros
are dissabled (msoAutomationSecurityForceDisable). Is there any way around
this? I thought that the idea of DisplayAlerts was to get around the
errors... I want to be able to open a word doc programatically (from a
server) and so don't want error messages...

I get the following error, and beneath is the VB.net code (basics only). I
hope someone can help as its doing my head in!

Thanks xx

Error:
'Title - Microsoft Visual Basic
'Text - The macros in this project are disabled. Please refer to the online
help or documentation of the host application to determine how to handle
macros.

Private Function BasicOpenWord(ByVal WordDocPath As String) As Boolean
Dim oWordApp As New Word.Application
Try
oWordApp.Visible = false
oWordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone'Don't want ANY alerts
'IF we open the doc with just the above, there is nothing to stop macros
running.
'When an app is started its default is msoAutomationSecurityLow -low
security. So...
Dim secAutomation As MsoAutomationSecurity


With oWordApp
secAutomation = .AutomationSecurity
.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
.AutomationSecurity =
oWordApp.AutomationSecurity.msoAutomationSecurityForceDisable

'#### You will get the following error on the next line : #####
.Documents.Open( _
FileName:=WordDocPath.ToString, _
ConfirmConversions:=False, _
ReadOnly:=True, _
AddToRecentFiles:=False, _
Format:=Word.WdOpenFormat.wdOpenFormatAuto)
.AutomationSecurity = secAutomation
End With


oWordApp.Documents.Close()
BasicOpenWord = True
Catch ex As Exception
...
BasicOpenWord = False
Finally
oWordApp.Quit()
oWordApp = Nothing
End Try
End Function
 
Z

zkid

Do you get the same message when you open the document manually?

If so, 2003 is a little strange that way. Sometimes you have to open your
docs/templates in 2003, make sure your reference libraries, if any, are
connected properly, and then save the document.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top