Help to create vba for "save as" and create PDF

goffy

New Member
Joined
Sep 10, 2012
Messages
10
Hi, I don't know anything about vba so i need some help here. I got this code:

Private Sub GemSom_Click()

MkDir "C:\Users\Martin\\\\\\\TEST" & Range("b6").Value & " " & Date

Dim Path As String
Dim FileName As String
FileName = Range("b6").Value & " " & Date
ActiveWorkbook.SaveAs "C:\Users\\\\\\\\\TEST" & Range("b6").Value & " " & Date & "" & FileName & ".xlsm"

ActiveSheet.Shapes("GemSom").Delete

End Sub

and it's working but; i do not want it in this folder. I need the new folde in the same folder as the workbook (ActiveWorkbook.Path or somthing like this) but I can't make it work.

Next i use this code for creating a PDF but it seem to complicated in my eys:

Private Sub CommandButton1_Click()

Dim i As Long, StrPath As String, StrFlNm As String, ArrNames
ArrNames = Array("Koebekontrakt")
StrPath = ActiveWorkbook.Path & ""
For i = 0 To UBound(ArrNames)
With Sheets(ArrNames(i))
StrFlNm = ArrNames(i) & Format(.Range("H7"), " mmmm yyyy")
.ExportAsFixedFormat Type:=xlTypePDF, FileName:=StrPath & StrFlNm, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
Next
End Sub

I need the PDF in the same folder as the workbook, but named as the "worksheedname & workbookname & date"

It's probably simpel but i cant find the code i need anywere, so if anyone can help I whould be greatfull :-)
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Code:
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]Sub ExportAsPDF()[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]Dim FolderPath As String[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]FolderPath = ThisWorkbook.Path & "\" &ActiveWorkbook.Name & " " & _[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]       Format(Now(),"dd.mm.yy hh.mm") & ".pdf"[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000] [/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000] ActiveWorkbook.ExportAsFixedFormatType:=xlTypePDF, Filename:=FolderPath, _[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]       openafterpublish:=False, ignoreprintareas:=False[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000] [/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT]
 
Upvote 0

Forum statistics

Threads
1,224,844
Messages
6,181,291
Members
453,030
Latest member
PG626

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