473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Convert Word Doc to PDF

28
I finally finished my word doc. But now I was told to create a PDF instead u.u

I tried this code:

Expand|Select|Wrap|Line Numbers
  1. Dim Word_App As Word.Application
  2. Set Word_App = New Word.Application
  3.  
  4. 'Create and fill the word document.
  5.  
  6. 'Save the document as PDF
  7. Word_App.ActiveDocument.ExportAsFixedFormat
  8. OutputFileName:=Replace(strPath, ".rtf", "") & " - " &
  9. vtCartas(iMarcaCartasIndividuais).strMatricula & ".pdf", _
  10. ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _
  11. OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, TO:=1, _
  12. Item:=wdExportDocumentContent, IncludeDocProps:=True,
  13. KeepIRM:=True, CreateBookmarks:=wdExportCreateNoBookmarks,
  14. DocStructureTags:=True, BitmapMissingFonts:=True, _
  15. UseISO19005_1:=False
But I'm getting this error:
Object Variable or With Block variable not set
Sep 12 '13 #1
9 5375
Rabbit
12,516 Expert Mod 8TB
I have to assume this code was not a direct copy and paste because you are missing line continuation characters. But after I put those in and change the path to one on my computer, the code runs just fine for me.

Make sure you didn't unset Word_App somewhere above that line.
Sep 12 '13 #2
Ghaleon
28
The Strange thing is that if I try this code:
Expand|Select|Wrap|Line Numbers
  1. Word_App.ActiveDocument.SaveAs filename:=strPath & "\doc1.doc"
It works, it saves the document as a .doc

but when I try to convert it to PDF it gives me the error =\
Sep 12 '13 #3
Rabbit
12,516 Expert Mod 8TB
Well, I don't know what else to try. It works fine for me after I fix the line continuation characters.
Sep 12 '13 #4
Ghaleon
28
Expand|Select|Wrap|Line Numbers
  1. '********************** WORD ****************************
  2. Private Word_App                    As Word.Application
  3. Private Word_Doc                    As Word.Document
  4. Private Word_Rtf_Doc                As Word.Document
  5. Private Word_Table                  As Word.Table
  6. Private Word_Range                  As Word.Range
  7. Private objRow                      As Row
  8. Private objCell                     As Cell
  9. Private sCellText                   As String
  10. Private Range                       As Range
  11. Private strPath                     As String
  12. Private iMarcaPaginas               As Integer
  13. Private iMarcaCartasIndividuais     As Integer
  14. Private strTempLogo                 As String
  15. '***************** END OF WORD ***************************
  16.  
  17.  
  18. Private Sub CreateDoc(strCarta As String)
  19.     On Error GoTo Trata_Erros    
  20.     Dim i                           As Integer
  21.     Dim strDebito                   As String
  22.     Dim strValor                    As String
  23.     Dim strVlMulta                  As String
  24.     Dim strVlSubTotal               As String
  25.  
  26.  
  27. strVlMulta = format(vtcJurosMultas(iLinha).cTotalTx, "#,##0.#0")
  28. strVlSubTotal = format(vtcJurosMultas(iLinha).cSubTotal, "#,##0.#0")
  29.  
  30. With ActiveDocument.Content.Find.Execute FindText:="
  31. debito>", ReplaceWith:="" & strDebito, format:=True,
  32.    Replace:=wdReplaceAll.Execute FindText:="<valor>",
  33.    ReplaceWith:="" & strValor, format:=True,
  34.    Replace:=wdReplaceAll.Execute FindText:="    <jurosmulta>",
  35.    ReplaceWith:="" & strVlMulta, format:=True,              Replace:=wdReplaceAll.Execute FindText:="<total>",
  36.    ReplaceWith:="" & strVlSubTotal, format:=True,
  37.    Replace:=wdReplaceAll.Execute FindText:="<totalf>",
  38.    ReplaceWith:="" & strVlSubTotal, format:=True,
  39.    Replace:=wdReplaceAll
  40. End With
  41.  
  42. Word_App.ActiveDocument.ExportAsFixedFormat OutputFileName:=Replace(strPath & "\doc1.doc",
  43. ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False,
  44. OptimizeFor:=wdExportOptimizeForPrint,Range:=wdExportAllDocument, From:=1, TO:=1, _
  45. Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True,CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:=True, _
  46. UseISO19005_1:=False
Could you take a look and see if you find something wrong?
Thanks.
Sep 12 '13 #5
Rabbit
12,516 Expert Mod 8TB
If this is a direct copy and paste of your code, then you are missing line continuation characters at 42 and 43.
Sep 12 '13 #6
Ghaleon
28
I'm using the continuation characters... Just deleted by mistake... Guess I'll have to find antoher way to make this conversion ;\
Sep 12 '13 #7
Rabbit
12,516 Expert Mod 8TB
In that case, if that's your entire code, Word_App is never initialized anywhere, it's only declared.
Sep 12 '13 #8
Ghaleon
28
It's working now \o/ I had to install an Add-in of MS-Word. But now, the characteres are a little bit strange... It still letters and you're able to read it. But it's a little strange you know ? is there a way to fix it ?
I'm trying to find a way/command to renderize the font, but didn't find it yet.

Look:

Sep 13 '13 #9
Rabbit
12,516 Expert Mod 8TB
We try to limit threads to one question each. Please create a new one for this question. As for the image, our firewalls block external storage sites, please upload the image to bytes instead.
Sep 13 '13 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ashutosh | last post by:
How can i convert Word file to txt file in ASP.NET using CSharp?
2
by: Johnny | last post by:
Hi, I want to take a word document and convert it to a postscript file in both a windows app or ASP.NET app. I've read that someone have done this in this newsgroup, but I have not been able to...
2
by: Dennis | last post by:
Looking for a method to programmatically convert (using vB) a Word doc to it's ASCII equivalent. I understand I'll lose all formatting, and that's okay Anyone out there have ideas Thaks ...
3
by: Jeff Mason | last post by:
Hi, I am looking for a software component that will allow me to convert a MS Word doc file to PDF from within my application. I'm using VB.NET and I'm currently doing the conversion...
2
by: Jeff Mason | last post by:
Hi, I am looking for a software component that will allow me to convert a MS Word doc file to PDF from within my application. I'm using VB.NET and I'm currently doing the conversion...
3
by: Chris Davoli | last post by:
I've got a requirement to build a page using MS WORD and then have the page show up on a web site. I know I can do a binary write and open up the WORD document in IE plugin. Don't really want to do...
13
by: kbperry | last post by:
Hi all, Background: I need some help. I am trying to streamline a process for one of our technical writers. He is using Perforce (version control system), and is constantly changing his word...
4
by: chandu | last post by:
Hello, i need to convert a word doc into xml format and need to store that xml doc in to a sqlserver database.. how to convert a word doc to xml and after retrieving that xml doc from database...
11
by: digbydog | last post by:
Hello, I have been looking at trying to find a third party product to convert a word document to a pdf is ASP DotNet. We previously did this in non web environnment using acrobat distiller but I...
3
by: mzmishra | last post by:
Hi, I have one application in c# .net 1.1. I like to convert word to pdf using Adobe Distiller . Can any body help me get some code samples in C# for the same?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.