MsgBox yes / no advice

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,731
Office Version
  1. 2007
Platform
  1. Windows
Morning,

I have the code below but would like some advise for a slight alteration please as i got lost with the yes / no part of it..

The code saves a screen shot in the form of a PDF file.
The Yes / No box is where im stuck.

Clicking No would just continue to save as normal

Clicking Yes would save the file as normal BUT also open & print it

Code:
Private Sub Generate_Pdf_Click()
    Dim strFileName As String
    
    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DR SCREEN SHOT PDF\" & Range("G13").Value & ".pdf"
    If Dir(strFileName) <> vbNullString Then
        MsgBox "INVOICE " & Range("G13").Value & " WAS NOT SAVED AS IT ALLREADY EXISTS", vbCritical + vbOKOnly, "GENERATE PDF FILE MESSAGE"
        Exit Sub
    End If
    
    With ActiveSheet
        .PageSetup.PrintArea = "$G$3:$O$61"
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
        MsgBox "INVOICE " & " WAS SAVED SUCCESSFULLY" & vbNewLine & "VIEW PDF FILE ?" & vbInformation + vbYesNo, "GENERATE PDF FILE MESSAGE"
                                                                                


        ActiveWorkbook.Save
    End With


End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi
Try like this
Code:
 x = MsgBox("INVOICE " & " WAS SAVED SUCCESSFULLY" & vbNewLine & "VIEW PDF FILE ?", vbInformation + vbYesNo, "GENERATE PDF FILE MESSAGE")
 If x = vbYes Then
 ' do some thig
 Else
  ' do what ever
 End If
 
Last edited:
Upvote 0
I understand that but it’s the actual writing it down I’m stuck with.
 
Upvote 0
Ok
in yuor case
change
Code:
MsgBox "INVOICE " & " WAS SAVED SUCCESSFULLY" & vbNewLine & "VIEW PDF FILE ?" & vbInformation + vbYesNo, "GENERATE PDF FILE MESSAGE"
ActiveWorkbook.Save
    End With
TO
Code:
    x = MsgBox("INVOICE " & " WAS SAVED SUCCESSFULLY" & vbNewLine & "VIEW PDF FILE ?", vbInformation + vbYesNo, "GENERATE PDF FILE MESSAGE")
    If x = vbYes Then
        ActiveWorkbook.Save
    End If
End With
 
Last edited:
Upvote 0
I’m lost by you reply.

No should be just save.

Yes should be save BUT also open file so I can view it.
 
Upvote 0
Hi,
Im currently with the code supplied below.

Where i have Yes was selected what do i replace it with so i can then print the saved pdf file.


Code:
Private Sub Generate_Pdf_Click()    Dim strFileName As String
    
    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DR SCREEN SHOT PDF\" & Range("G13").Value & ".pdf"
    If Dir(strFileName) <> vbNullString Then
        MsgBox "INVOICE " & Range("G13").Value & " WAS NOT SAVED AS IT ALLREADY EXISTS", vbCritical + vbOKOnly, "GENERATE PDF FILE MESSAGE"
        Exit Sub
    End If
    
    With ActiveSheet
        .PageSetup.PrintArea = "$G$3:$O$61"
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
        pdf = MsgBox("INVOICE " & " WAS SAVED SUCCESSFULLY" & vbNewLine & vbNewLine & "DO YOU WANT TO PRINT THE PDF FILE ?", vbExclamation + vbYesNo, "GENERATE PDF FILE MESSAGE")
        If pdf = vbYes Then
        MsgBox "Yes was selected"
        Else
        ActiveWorkbook.Save
        End If
    End With


End Sub
 
Upvote 0
I applied the following for it to work,thanks

Code:
ActiveWindow.SelectedSheets.PrintOut Copies:=1
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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