Converting Excel Sheet to PDF & then that PDF to Word

SaifnJeans

New Member
Joined
Jun 5, 2022
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hi Respected All Excel Experts, I need to convert Excel Sheet to PDF and then that PDF to Word. I have somehow managed to make and get following code through which my PDF file is getting saved in specific Folder with Specific name and even opening Word File But getting error in last 2 lines of the Code. Any help in this regard will really be appreciated;


Sub SaveAspdf()

Dim Path As String
Dim Deal As String
Dim Agent As String
Dim DocType As String
Dim dt_issue As Date
Dim FName As String

Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Document")

Dim fso As New FileSystemObject
Dim fo As Folder
Dim f As File

Dim wa As New Word.Application
Dim doc As Word.Document
wa.Visible = True

Dim pdf_path As String
Dim word_path As String


Path = Range("D4")
Deal = Range("C3")
Agent = Range("C4")
DocType = Range("C5")
dt_issue = Range("B6")

FName = Deal & " " & Agent & " " & DocType
Sheets("Document").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & FName, OpenAfterPublish:=False

pdf_path = sh.Range("D4").Value
word_path = sh.Range("D5").Value


Set doc = wa.Documents.Open(f.Path)
doc.SaveAs2 (word_path & "\" & Replace(f.Name, ".pdf", ".docx"))
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
getting error in last 2 lines of the Code. Any help in this regard will really be appreciated;
You can only get an error on one line because then execution stops. When asking for help with a runtime error always give the error number and error description.

Set doc = wa.Documents.Open(f.Path)
I don't know what error you are getting but the variable f is never assigned a value in your code so it will cause an error when you try to refer to f.path. I am not quite sure what you are trying to open so I don't know how to correct this code.

Also, do you need that PDF file? Or are you just using it as an intermediate step to get Excel content into a Word file? If so you can just copy from Excel and paste to Word.
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,382
Members
448,889
Latest member
TS_711

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