Relative instead of Absolute paths in Excel VBA

前端 未结 8 933
眼角桃花
眼角桃花 2020-12-05 04:10

I have written an Excel VBA macro which imports data from a HTML file (stored locally) before performing calculations on the data.

At the moment the HTML file is ref

8条回答
  •  -上瘾入骨i
    2020-12-05 04:40

    i think this may help. Below Macro checks if folder exists, if does not then create the folder and save in both xls and pdf formats in such folder. It happens that the folder is shared with the involved people so everybody is updated.

    Sub PDF_laudo_e_Prod_SP_Sem_Ajuste_Preco()
    '
    ' PDF_laudo_e_Prod_SP_Sem_Ajuste_Preco Macro
    '
    
    '
    
    
    Dim MyFolder As String
    Dim LaudoName As String
    Dim NF1Name As String
    Dim OrigFolder As String
    
    MyFolder = ThisWorkbook.path & "\" & Sheets("Laudo").Range("C9")
    LaudoName = Sheets("Laudo").Range("K27")
    NF1Name = Sheets("PROD SP sem ajuste").Range("Q3")
    OrigFolder = ThisWorkbook.path
    
    Sheets("Laudo").Select
    Columns("D:P").Select
    Selection.EntireColumn.Hidden = True
    
    If Dir(MyFolder, vbDirectory) <> "" Then
    Sheets("Laudo").ExportAsFixedFormat Type:=xlTypePDF, filename:=MyFolder & "\" & LaudoName & ".pdf", Quality:=xlQualityMinimum, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
    False
    
    Sheets("PROD SP sem ajuste").ExportAsFixedFormat Type:=xlTypePDF, filename:=MyFolder & "\" & NF1Name & ".pdf", Quality:=xlQualityMinimum, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
    False
    
    ThisWorkbook.SaveAs filename:=MyFolder & "\" & LaudoName
    
    Application.DisplayAlerts = False
    
    ThisWorkbook.SaveAs filename:=OrigFolder & "\" & "Entregas e Instrucao Barter 2015 - beta"
    
    Application.DisplayAlerts = True
    
    Else
    MkDir MyFolder
    Sheets("Laudo").ExportAsFixedFormat Type:=xlTypePDF, filename:=MyFolder & "\" & LaudoName & ".pdf", Quality:=xlQualityMinimum, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
    False
    
    Sheets("PROD SP sem ajuste").ExportAsFixedFormat Type:=xlTypePDF, filename:=MyFolder & "\" & NF1Name & ".pdf", Quality:=xlQualityMinimum, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
    False
    
    ThisWorkbook.SaveAs filename:=MyFolder & "\" & LaudoName
    
    Application.DisplayAlerts = False
    
    ThisWorkbook.SaveAs filename:=OrigFolder & "\" & "Entregas e Instrucao Barter 2015 - beta"
    
    Application.DisplayAlerts = True
    
    End If
    
    Sheets("Laudo").Select
    Columns("C:Q").Select
    Selection.EntireColumn.Hidden = False
    Range("A1").Select
    
    End Sub
    

提交回复
热议问题