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

goffy

New Member
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 :)
 

arunsjain

Board Regular
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]
 

Some videos you may like

This Week's Hot Topics

Top