Results 1 to 3 of 3

Thread: Help to create vba for "save as" and create PDF
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Sep 2012
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    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

  2. #2
    Board Regular
    Join Date
    Apr 2016
    Posts
    73
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help to create vba for "save as" and create PDF

    Code:
    Sub ExportAsPDF()
    Dim FolderPath As String
    FolderPath = ThisWorkbook.Path & "\" &ActiveWorkbook.Name & " " & _
           Format(Now(),"dd.mm.yy hh.mm") & ".pdf"
    
     ActiveWorkbook.ExportAsFixedFormatType:=xlTypePDF, Filename:=FolderPath, _
           openafterpublish:=False, ignoreprintareas:=False
    
    End Sub

  3. #3
    New Member
    Join Date
    Sep 2012
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help to create vba for "save as" and create PDF

    Thank you, that solved my problem with the PDF.

    The Save.as i got working as well

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •