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
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