Relative instead of Absolute paths in Excel VBA

Relative instead of Absolute paths in Excel VBA

Asked on January 11, 2019 in Excel.
Add Comment


  • 3 Answer(s)

    This solution will explain about relative instead of Absolute paths in Excel VBA

    Workbooks.Open FileName:= ThisWorkbook.Path & "\TRICATEndurance Summary.html"
    
    Answered on January 11, 2019.
    Add Comment

    For the relative path root, You can use the following :

    ActiveWorkbook.Path
    ThisWorkbook.Path
    App.Path
    
    Answered on January 11, 2019.
    Add Comment

    By implement Browser Button to the users fore more adjustability,

    And use this following command :

    Private Sub btn_browser_file_Click()
    Dim xRow As Long
    Dim sh1 As Worksheet
    Dim xl_app As Excel.Application
    Dim xl_wk As Excel.Workbook
    Dim WS As Workbook
    Dim xDirect$, xFname$, InitialFoldr$
    InitialFoldr$ = "C:\"
    With Application.FileDialog(msoFileDialogFolderPicker)
        .InitialFileName = Application.DefaultFilePath & "\"
        .Title = "Please select a folder to list Files from"
        .InitialFileName = InitialFoldr$
        .Show
        Range("H13").Activate
        If .SelectedItems.Count <> 0 Then
           xDirect$ = .SelectedItems(1) & "\"
            Range("h12").Value = xDirect$
           xFname$ = Dir(xDirect$, 7)
           Do While xFname$ <> ""
           If (Format(FileDateTime(xDirect$ & "\" & xFname$), "MM/DD/YYYY") > Format(Range("H10").Value, "MM/DD/YYYY")) Then
           ActiveCell.Offset(xRow) = xFname$
           xRow = xRow + 1
           xFname$ = Dir
           Else
           xFname$ = Dir
           xRow = xRow
         End If
        Loop
       End If
    End width
    
    Answered on January 11, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.