Type mismatch "Run-time error '13'"

Banimo

New Member
Joined
Sep 22, 2014
Messages
7
I'm currently working on a solution to:

  • Open a specified word document
  • Complete a mail merge with specified table in excel
  • Save results in '.pdf. format

I have got this working up until i try to save the results as PDF, i get a run-time error '13': Type mismatch.

Heres my code:

--------------

Private Sub OpenWrd()

Application.DisplayAlerts = False

Set wdApp = Word.Application

Set doc = Word.Documents

Set wdApp = CreateObject("Word.Application")

wdApp.Documents.Add ("G:\Everyone\QP12 JSY Maturity Advice.docx")
wdApp.Visible = True
wdApp.WindowState = wdWindowStateMaximize


wdApp.ActiveDocument.MailMerge.OpenDataSource Name:="\\sbojsyfps001\data\Home\banimb\Data\Documents\BenAdmin\Save test (sub)\TestSave2.xlsx" _

With wdApp.ActiveDocument.MailMerge
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With



Dim filename As String
Set myDoc = Word.Documents

Word.Documents.Save "\\sbojsyfps001\data\Home\banimb\Data\Documents\BenAdmin\MergeTestSave\TestSave3" & ".pdf"


End Sub

-----------
The code that is highlighted is the

"Word.Documents.Save "\\sbojsyfps001\data\Home\banimb\Data\Documents\BenAdmin\MergeTestSave\TestSave3" & ".pdf""

Any clues?
Ta
 

Some videos you may like

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,275
Try this (not tested).

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] OpenWrd()
    
    [color=darkblue]Dim[/color] wdApp [color=darkblue]As[/color] Word.Application, MyDoc [color=darkblue]As[/color] Word.Document
    
    [color=darkblue]Set[/color] wdApp = CreateObject("Word.Application")
    wdApp.Visible = [color=darkblue]True[/color]
    wdApp.WindowState = wdWindowStateMaximize
    
    [color=darkblue]Set[/color] MyDoc = wdApp.Documents.Add("G:\Everyone\QP12 JSY Maturity Advice.docx")
    
    [color=darkblue]With[/color] MyDoc
        
        [color=darkblue]With[/color] .MailMerge
            .OpenDataSource Name:="\\sbojsyfps001\data\Home\banimb\Data\Documents\BenAdmin\Save test (sub)\TestSave2.xlsx"
            .SuppressBlankLines = [color=darkblue]True[/color]
            [color=darkblue]With[/color] .DataSource
                .FirstRecord = wdDefaultFirstRecord
                .LastRecord = wdDefaultLastRecord
            [color=darkblue]End[/color] [color=darkblue]With[/color]
            .Execute Pause:=[color=darkblue]False[/color]
        [color=darkblue]End[/color] [color=darkblue]With[/color]
        
        .SaveAs2 "\\sbojsyfps001\data\Home\banimb\Data\Documents\BenAdmin\MergeTestSave\TestSave3" & ".pdf", wdFormatPDF
        
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,108,501
Messages
5,523,290
Members
409,508
Latest member
Afc

This Week's Hot Topics

Top