Hello, I have only been using VB for under a week so can i ask for a dumed down explenation.
Way i am trying to achive is a Quote with some cells information that is whited out or hidden when printing. I have that working fine.
The code that i have compiled together from the web ill post below.
What i would like to get is after the print preview is closed a msgbox asking if you would like to print as a .PDF file before the text borders are reset.
Sub Button3_Click()
With ActiveSheet
'save the file as a mashed mutapil cell name and date
ActiveWorkbook.SaveAs "C:\" & Sheet1.Range("f4").Value & "_" & Sheet1.Range("f5").Value & "_" & Format$(Date, "dd-mm-yy") & ".xlsm", FileFormat:=xlNormal
' remove cell border
Range("g23:J32").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
'repair cell border of dameged layout
Range("G23:G32").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
' change background and tect colour to white
.Range("g1:g100,h1:h100,i1:i100,j1:j100,a23:a32").Font.ColorIndex = 2
.Range("g1:g100,h1:h100,i1:i100,j1:j100,a23:a32").Interior.ColorIndex = 2
'print preview
ActiveWindow.SelectedSheets.PrintPreview
'message box asking if ok to print
MsgBox "would you like to Print", vbYesNo
If answer <> vbYes Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1
If answer <> vbNo Then
End
End If
' replace border
Range("g23,h23,i23,j23,g24:g32,h24:h32,i24:i32,j24:j32").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
' change background white and tect colour to black
.Range("g1:g100,h1:h100,i1:i100,j1:j100,a23:a32").Font.ColorIndex = 1
.Range("g1:g100,h1:h100,i1:i100,j1:j100,a23:a32").Interior.ColorIndex = 2
End With
End Sub
i have found some code for .PDF printing. though i cant figure out how a msgbox vbyesno works so i accept i need help.
Sub PrintWholeWorksheetToPDF()
Dim sPSFileName As String ' Name of PS to be created
Dim sPDFFileName As String 'Name of PDF to be created
Dim sJobOptions As String
Dim sCurrentPrinter As String 'Same current printer choice to resume at end
Dim sPDFVersionAndPort As String 'Version of Adobe
Dim appDist As cAcroDist
Set appDist = New cAcroDist
sCurrentPrinter = Application.ActivePrinter 'Save the currently active printer
sPDFVersionAndPort = "Adobe PDF on Ne01:"
sPSFileName = ThisWorkbook.Path & "\MyFileName" & ".ps" 'Name of PS file
sPDFFileName = ThisWorkbook.Path & "\MyFileName" & ".pdf" 'Name of PDF
ThisWorkbook. Sheets.PrintOut ActivePrinter:=sPDFVersionAndPort, _
PrintToFile:=True, PrToFileName:=sPSFileName 'Prints to PS
Call appDist.odist.FileToPDF(sPSFileName, sPDFFileName, sJobOptions)
'Creates PDF
Kill sPSFileName 'Removes PS
Application.ActivePrinter = sCurrentPrinter 'Change back to the original printer
End Sub
Thankyou.
Bookmarks