Sean Winder
New Member
Hi guys,
So for my A2 coursework I have to create a spreadsheet for a business to use to keep track of orders, and I have made one that I quite like. On one of the sheets, I have an auto-generating invoice, that pulls data from the order form and concatenates it. To the right of the invoice, I have two macro buttons, one to print the invoice, and one to save & open it in PDF format, so I can email it. However, due to the way that this VBA code currently works, I have to change the macro every time I transfer the file to a new PC, since I need to make it work on multiple machines.
Here's the code:
Essentially, this is unprotecting the worksheet, selecting the cells, removing their aesthetic border, exporting them, and then re-doing everything that was undone.
This works fine, however the bit shown in bold is what's causing me trouble, the fact that it will only save in this location.
What I really want it to do is detect where the spreadsheet has been loaded from, and save in the same directory as that.
Any help will be greatly appreciated.
Sean
So for my A2 coursework I have to create a spreadsheet for a business to use to keep track of orders, and I have made one that I quite like. On one of the sheets, I have an auto-generating invoice, that pulls data from the order form and concatenates it. To the right of the invoice, I have two macro buttons, one to print the invoice, and one to save & open it in PDF format, so I can email it. However, due to the way that this VBA code currently works, I have to change the macro every time I transfer the file to a new PC, since I need to make it work on multiple machines.
Here's the code:
Code:
Sub SaveAsPDF()
'
' SaveAsPDF Macro
'
'
Range("B3:I38").Select
ActiveSheet.Unprotect
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
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"H:\School\Year 13\ICT\Mr Mordue\Contrast Photography Invoice.pdf", Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Essentially, this is unprotecting the worksheet, selecting the cells, removing their aesthetic border, exporting them, and then re-doing everything that was undone.
This works fine, however the bit shown in bold is what's causing me trouble, the fact that it will only save in this location.
What I really want it to do is detect where the spreadsheet has been loaded from, and save in the same directory as that.
Any help will be greatly appreciated.
Sean