ChDir pull file path

mysticmario

Active Member
Joined
Nov 10, 2021
Messages
323
Office Version
  1. 365
Platform
  1. Windows
Hi, Whenever i make changes to certain sheet in my excel I have an auto publish macro which creates html file out of it.
It works great cause the directory I Have put is taken from my PC. However, different people use this file from different PCs and despite this file being on google drive everyone has different path to it how can I make this Publish() sub to get its ChDir using the path it was opened from?
VBA Code:
Sub publish()
    ChDir "G:\Mój dysk\ArtProInfo v1.5_Shared"
    With ActiveWorkbook.PublishObjects("ArtProInfo v1.5_8106")
        .FileName = "G:\Mój dysk\ArtProInfo v1.5_Shared\index.html"
        .publish (False)
        .AutoRepublish = False
    End With
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
if the file is already open then you could use
Application.ThisWorkbook.Path for just the path itself (without the workbook name) or
Application.ThisWorkbook.FullName for the path with the workbook name.
 
Upvote 0
Solution
I have sth like this
VBA Code:
Sub publish()





    ChDir (Application.ActiveWorkbook.Path)

    With ActiveWorkbook.PublishObjects("ArtProInfo v1.5_8106")

        .FileName (Application.ActiveWorkbook.Path & "\" & "index.html*")

        .publish (False)

        .AutoRepublish = False

    End With

End Sub
but it seems to not work properly
 
Upvote 0
I have sth like this
VBA Code:
Sub publish()





    ChDir (Application.ActiveWorkbook.Path)

    With ActiveWorkbook.PublishObjects("ArtProInfo v1.5_8106")

        .FileName (Application.ActiveWorkbook.Path & "\" & "index.html*")

        .publish (False)

        .AutoRepublish = False

    End With

End Sub
but it seems to not work properly
when you say not work properly what exactly do you mean, what does it not do properly
 
Upvote 0
when you say not work properly what exactly do you mean, what does it not do properly
invalid use of property for .filename
i tried this aswell but same result
VBA Code:
Dim cDir As String
cDir = Application.ActiveWorkbook.Path
    ChDir (Application.ActiveWorkbook.Path)
    With ActiveWorkbook.PublishObjects("ArtProInfo v1.5_8106")
        .FileName cDir & "\" & "index.html*"
        .publish (False)
        .AutoRepublish = False
    End With
End Sub
 
Upvote 0
invalid use of property for .filename
i tried this aswell but same result
VBA Code:
Dim cDir As String
cDir = Application.ActiveWorkbook.Path
    ChDir (Application.ActiveWorkbook.Path)
    With ActiveWorkbook.PublishObjects("ArtProInfo v1.5_8106")
        .FileName cDir & "\" & "index.html*"
        .publish (False)
        .AutoRepublish = False
    End With
End Sub
I can see you have changed "thisworkbook" to "Activeworkbook" this could be the issue.
 
Upvote 0
you have also deleted the "=" after .filename
Such a tiny piece of code and so many issues... Now this happens:
1643964046720.png


code:
VBA Code:
Sub publish()
    ChDir (Application.ThisWorkbook.Path)
    With ActiveWorkbook.PublishObjects("ArtProInfo v1.5_8106")
        .FileName = Application.ThisWorkbook.Path & "\" & "index.html*"
        .publish (False)
        .AutoRepublish = False
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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