HI Guys,
I've been trying to create mail merge functionality via button in Qlikview.
Well i've got this vba code, i've tested it externally and it works lovely.
Sub wordtest()
Set objword = CreateObject("Word.Application")
objword.Documents.Open ("C:\Users\ross turner.DOMAIN\Desktop\Policy.doc")
objword.Visible = True
With objword.ActiveDocument.MailMerge
.OpenDataSource Name:="C:\Users\ross turner.DOMAIN\Desktop\mailmerge.xls", _
ReadOnly:=True, _
SQLStatement:="SELECT * FROM [Sheet1$]"
.Execute
objword.ActiveDocument.PrintOut
objword.Quit (0)
End With
End Sub
So i've been trying to combine it with a button in Qlikview to do the whole shebang, so you make your selection criteria and then hit the button and voila....
I've set the User Security security to allow CreateObject and File access
![Capture1.JPG.jpg](/legacyfs/online/56581_Capture1.JPG.jpg)
Also set the Document Security security to override security
![Capture2.JPG.jpg](/legacyfs/online/56585_Capture2.JPG.jpg)
So here is the script and i can see it creating the winword.exe in task manger... but it throws a "Expected Statement" Error
Sub wordtest()
'First Get The Table Data
Set obj = ActiveDocument.GetSheetObject("TB08")
'Export Table Data
obj.ExportBiff "C:\Users\ross turner.DOMAIN\Desktop\mailmerge.xls"
'Remove Data
Set obj = nothing
'Open Word
Set objword = CreateObject("Word.Application")
'Load Word Doc
objword.Documents.Open ("C:\Users\ross turner.DOMAIN\Desktop\Policy.doc")
'Make Visible for Testing
objword.Visible = True
With objword.ActiveDocument.MailMerge
.OpenDataSource Name:="C:\Users\ross turner.DOMAIN\Desktop\mailmerge.xls",_
ReadOnly:=True,_
SQLStatement:="SELECT * FROM [Sheet1$]"
.Execute
objword.ActiveDocument.PrintOut
objword.Quit (0)
End With
End Sub
![Capture.JPG.jpg](/legacyfs/online/56580_Capture.JPG.jpg)
any help with this would be greatly appreciated.
Cheer
Ross