Opening pdf now shows message box

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
I am using the supplied code below.

When i run the code i now see the message shown as per screen shot supplied.
The pdf is saved & i see no other messages or errors so not sure why this message is being shown.

Adobe Reader is used.
I go to the path as mentioned & the saved pdf is there & i am able to open it no problem.

Anybody have info on this please or do you see an error in the code.

Thanks


Rich (BB code):
Private Sub CommandButton1_Click()
  Dim sPath As String
  Dim strFileName As String
  Dim sh As Worksheet
  
  If TextBox1 = "" Then
  MsgBox "YOU DID NOT ENTER A CUSTOMERS NAME", vbCritical, "NO NAME ENTERED ON SHEET"
  TextBox1.SetFocus
  Exit Sub
    
  End If
  
  With ThisWorkbook.Worksheets("PRINT LABELS")
    .Range("B3") = Me.TextBox1.Text ' ENTERS CUSTOMERS NAME TO WORKSHEET
    .Range("E3") = Format(DateSerial(CLng(Me.cboYear.Value), Me.cboMonth.ListIndex + 1, Me.cboDay.Value), "long date")
  End With
  Unload PrinterForm
                                                                             
  With ActiveSheet
    If .Range("AB1") = "" Then
      MsgBox "NO CODE SHOWN TO GENERATE PDF", vbCritical, "NO CODE ON SHEET TO CREATE PDF"
      Exit Sub
    End If
    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & " " & Format(.Range("E3").Value, "dd-mm-yyyy") & ".pdf"
    .Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
    MsgBox "PDF HAS NOW BEEN GENERATED", vbInformation + vbOKOnly, "GENERATE PDF FILE MESSAGE"
    
  End With
  
        sPath = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\"
        strFileName = sPath & Range("B3").Value & " " & Format(Range("E3").Value, "dd-mm-yyyy") & ".pdf"

  If Dir(strFileName) <> vbNullString Then
    ActiveWorkbook.FollowHyperlink strFileName
    Else
    MsgBox ("not found")
  End If
    
 
End Sub
 

Attachments

  • EaseUS_2023_05_17_07_41_31.jpg
    EaseUS_2023_05_17_07_41_31.jpg
    26.6 KB · Views: 9
I sell Land Rover keys & this pdf sheet include the keys code & various other info.
I then put this printed pdf in package posting
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
That doesn't really answer the question. Why do you need an actual pdf rather than just printing the sheet(s) you make the pdf from currently?
 
Upvote 0
Ok i now understand.

So if you have another suggestion then i willing to use it.

I mean you are saying to save as a word doc & just print that.

If so please advise code & i will use that
 
Upvote 0
No, I'm saying just print the workbook. Do you actually need to save this data as a separate file at all?
 
Upvote 0
Yes
I need a hard copy hence the pdf on my pc

I also print it for the customer
 
Upvote 0
Can you advise some code & im then done i believe.

Code in use is shown below.
The code in red shown should print the active sheet print area but nothing happens at all.
Last part of the working code i see is the msgbox PDF HAS NOW BEEN GENERATED.
So now lets just print what i see on the screen without having to look at the pdf saved in the folder on the pc

This i believe should now fix it

Rich (BB code):
Private Sub CommandButton1_Click()
  Dim sPath As String
  Dim strFileName As String
  Dim sh As Worksheet
  
  If TextBox1 = "" Then
  MsgBox "YOU DID NOT ENTER A CUSTOMERS NAME", vbCritical, "NO NAME ENTERED ON SHEET"
  TextBox1.SetFocus
  Exit Sub
    
  End If
  
  With ThisWorkbook.Worksheets("PRINT LABELS")
    .Range("B3") = Me.TextBox1.Text
    .Range("E3") = Format(DateSerial(CLng(Me.cboYear.Value), Me.cboMonth.ListIndex + 1, Me.cboDay.Value), "long date")
    
  End With
  Unload PrinterForm
                                                                             
  With ActiveSheet
    If .Range("AB1") = "" Then
      MsgBox "NO CODE SHOWN TO GENERATE PDF", vbCritical, "NO CODE ON SHEET TO CREATE PDF"
      Exit Sub
    End If
    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & " " & .Range("AB1").Value & " " & Format(.Range("E3").Value, "dd-mm-yyyy") & ".pdf"
    .Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
    MsgBox "PDF HAS NOW BEEN GENERATED", vbInformation + vbOKOnly, "GENERATE PDF FILE MESSAGE"
    

    With ActiveSheet
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False

 End With
 End With
End Sub
 
Upvote 0
This fixed it
With ActiveSheet

ActiveWindow.SelectedSheets.PrintOut copies:=1
 
Upvote 0

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

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