Link to home
Start Free TrialLog in
Avatar of Rushikkumar Patel
Rushikkumar Patel

asked on

Macro Path finder is not working for another user

My question is:

I have this path finder code in my macro which is:

LocalAddress = Application.ThisWorkbook.FullName

It is working fine for getting my file but when i pass this code to my team member who works from different computer and drive, it is not working for him.

Please help in this code line so that it can work with any computer.

thank you so much in advance.
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Is LocalAddress defined as a String somewhere?

It is deigned to return the workbook name and it does in my workbook.

Please describe what you mean by "it is not working for him".
Avatar of Rushikkumar Patel
Rushikkumar Patel

ASKER

Tes. It is defined as string.

When other user use this code he got the error 76, path could not found.
It must be something else that is the cause of the error, because that's standard code and as I said it works for me and I'm definitely on a different computer and drive from you:). Please post the whole macro.
Dim SharepointAddress As String
Dim LocalAddress As String
Dim objNet As Object
Dim FS As Object

SharepointAddress = "\\mysite.sharepoint.com\sites\xyz-uat\a1docsuat"  & "\"          ' Where you will enter your location path
LocalAddress = "your file path"                                      ' Where you will enter the file path, ex: Excel file
Set objNet = CreateObject("WScript.Network")
Set FS = CreateObject("Scripting.FileSystemObject")
If FS.FileExists(LocalAddress) Then
FS.CopyFile LocalAddress, SharepointAddress
End If
Set objNet = Nothing
Set FS = Nothing

I have used this code from this site.
If you want LocalAddress to contain just the address then do this

LocalAddress = Application.Path

If you want path and file name (which I think you do) then do this.

LocalAddress = Application.Path & "\" & Application.ThisWorkbook.FullName
I will check this again on my work.

But why it works on mine computer and not for other user?

Thanks.
I don't know.
Application.ThisWorkbook.FullName will return a valid file path only if the file is saved. Are you sure that the user saved the file before testing the code?
I will check it tomorrow.

Thank you.
Neeraj is correct.
I have excel 2010 and other user have excel 2016. Does it affect anyway in not running the code on 2016 excel?
The file was saved. Still it is not working for other user.

Any other area i might need to look for the problems? Is it something to do with sharepoint access?

thanks.
What do you mean by "not working"?
User got Run time error: 76 Path not found.
Have the user do this:
1) Add the following line of code just before the LocalAddress = Application.ThisWorkbook.FullName line
2) Debug.Print LocalAddress = Application.ThisWorkbook.FullName
3) Run the macro
4) Go to Visual Basic via Alt+F11
5) Go to the Immediate Window vis Ctrl+G
6) Tell us what is in the Immediate Window
Other use have to enter their Sharepoint site credential manually every time they go use Connect and export option while I do not have to.

Does it affect his macro because of not allowing the access through that credential part?

Thank you.

Also i have asked user to do above steps. Once i  will get the reply i will post it.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.