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
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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:
Upvote 0

Forum statistics

Threads
1,217,498
Messages
6,136,993
Members
450,037
Latest member
Tao86

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top