View Single Post
 
Old 07-10-2015, 11:18 AM
Errol Isenberg Errol Isenberg is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Jul 2015
Location: Florida
Posts: 2
Errol Isenberg is on a distinguished road
Default Program-generated .pdf file unable to be opened

Hello, all you Microsoft Word experts. This is from a Microsoft Excel 2013 Specialist who is looking to improve in Word.
I have a Word document that I want to save as a .pdf file.When I click on FILE è Save As è and then choose “PDF” from the Save as Type drop-down menu, I get a .pdf file that opens with no problem.
The Word document has as the first word in the title line a field with anywhere from 1 to 7 digits, which is used as the name of the file.
When I try to automate the process, the .pdf file is created but cannot be opened; the highlighted error message below is displayed when an attempt is made to open the program-generated .pdf file – I understand this is due to the extraneous byte situation.As far as I can tell there are no extraneous bytes in front of the file.
Adobe Reader could not open ‘3224412.pdf’ because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn’t correctly decoded).
The relevant files are attached; the Word document with its macro (3224412 word doc.docm), a good version of the .pdf file (3224412 word doc.pdf), and the corrupted version of the .pdf file (3224412.pdf).
The program code is shown below as well as being included in the attached file.
Code:
Sub SaveDocument()
' this program saves the document in the Suntax Uploads folder on the user's desktop
Dim rng_claimant_id As Range
Dim str_claimant_id As String
Dim str_user_name As String
str_user_name = Application.UserName
Const const1 As String = "C:\Users\"
Const const2 As String = "\Desktop\Suntax Uploads\"
Const const3 As String = ".pdf"
Set rng_claimant_id = ActiveDocument.Range(Start:=ActiveDocument.Words(1).Start, End:=ActiveDocument.Words(1).End)
If Len(rng_claimant_id) = 8 Then
  str_claimant_id = Left(rng_claimant_id, 7)
Else
  If Len(rng_claimant_id) = 7 Then
    str_claimant_id = Left(rng_claimant_id, 6)
  Else
    If Len(rng_claimant_id) = 6 Then
      str_claimant_id = Left(rng_claimant_id, 5)
    Else
      If Len(rng_claimant_id) = 5 Then
        str_claimant_id = Left(rng_claimant_id, 4)
      Else
        If Len(rng_claimant_id) = 4 Then
          str_claimant_id = Left(rng_claimant_id, 3)
        Else
          If Len(rng_claimant_id) = 3 Then
            str_claimant_id = Left(rng_claimant_id, 2)
          Else
            str_claimant_id = Left(rng_claimant_id, 1)
          End If
        End If
      End If
    End If
  End If
End If
ActiveDocument.SaveAs2 FileName:=const1 & str_user_name & const2 & str_claimant_id & const3
' ActiveDocument.SaveAs2 "C:\Users\isenbee\Desktop\Suntax Uploads\3224412.pdf"
Code:
End Sub

The operating system I am using is Windows 7 Enterprise 64-bit.
Can anyone tell me how to programmatically generate the .pdf file so that it can be opened properly? I am not allowed to modify any registry settings. Thank you very much for your help.
Attached Files
File Type: docm 3224412 word doc.docm (186.6 KB, 10 views)
File Type: pdf 3224412 word doc.pdf (259.5 KB, 8 views)
File Type: pdf 3224412.pdf (186.6 KB, 8 views)

Last edited by macropod; 07-10-2015 at 07:56 PM. Reason: Added code tags & formatting
Reply With Quote