LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default Running Word to Save as PDF

I am obviously doing something wrong... I am trying desperately to avoid having to activate the Microsoft Word XXXX Object Library as this may possibly be used by others in the future and you know trying to describe how to activate references can be difficult...
The error occurs in the .ExportAsFixedFormat line, and I dunno what's wrong.. I recorded a save-do-pdf event from word itself and those are the lines I was given...
I'm running office 2003 on Win7 Pro also.



Sub DocToPDF()
Dim WordObject As Object
Dim WordDoc As Object
Dim ws As Worksheet
Dim path As String
Dim fname As String, filename2 As String, name As String, ext As String
Set WordObject = CreateObject("word.application")
WordObject.Visible = False

Set ws = ActiveSheet
path = ws.Range("a1").Value
If Right(path, 1) < "\" Then
path = path & "\"
End If
For i = 5 To ws.UsedRange.Rows.count
name = ws.Range("b" & i).Value
ext = Mid(name, InStr(name, "."), Len(name) - InStr(name, ".") + 1)
fname = path & name
filename2 = Replace(fname, ext, ".pdf")
Set WordDoc = WordObject.documents.Add(fname)
With WordDoc
.ExportAsFixedFormat OutputFileName:=filename2, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False
.Close
End With
Next i
Set WordObject = Nothing
Set WordDoc = Nothing
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Test if Word is running John Excel Programming 7 April 13th 09 06:22 PM
when i save xls file, debug script is running and canno't save fil Imtiaz Excel Discussion (Misc queries) 1 July 16th 05 03:47 PM
How to save excel spreadsheet and word doc with one save CEP Excel Programming 0 April 29th 05 10:29 PM
running a word macro from xl steve Excel Programming 0 May 3rd 04 02:33 PM
running a word macro from xl Steve Excel Programming 0 April 30th 04 08:56 PM


All times are GMT +1. The time now is 06:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"