code is not working.

H

Heera Chavan

Hi All,

This code checks the file path of workbook as it should be always on shared
drive.

Function PathAndName() As Boolean

Dim WBPath As String

WBPath = ThisWorkbook.Sheets("Data").Range("B3").Value
'the string length is more the 100 carectors in length.

If ThisWorkbook.Path <> WBPath Then

MsgBox "This workbook is not correct path."
Exit Function

End If

End Function

This small funtion is troubling me a lot. It works on some machines and it
doesnt work on some. Some times it works on my machine and some times i
doesnt.

Kindly help
Heera Chavan
 
J

Joel

The function doesn't return a value and if on a worksheet will not run since
no parameter is pass to the function. worksheet functions only get called
when a dependency is updated. The dependency is the passed parameter which
doesn't exist.

Function PathAndName() As Boolean

Dim WBPath As String

WBPath = ThisWorkbook.Sheets("Data").Range("B3").Value
'the string length is more the 100 carectors in length.

If ThisWorkbook.Path <> WBPath Then

MsgBox "This workbook is not correct path."
PathAndName = False
else
PathAndName = True
End If

End Function


I would change the code to pass B3

=PathAndName(Data!B3)

Function PathAndName(WBPath as string) As Boolean

'the string length is more the 100 carectors in length.

If ThisWorkbook.Path <> WBPath Then

MsgBox "This workbook is not correct path."
PathAndName = False
else
PathAndName = True
End If

End Function
 
P

p45cal

Apart from Joel's observations, I suspect that the "works on som
machines and it doesnt work on some" come from the shared driv
location. Perhaps some machines have a different drive letter for th
drive or have the folder mapped differently.

I did a google for 'unc path excel vba' and the very first entry prove
the most useful:
'dailydoseofexcel
(http://www.dailydoseofexcel.com/archives/2006/06/21/unc-path/)

Specifically this:
application.CommandBars("Web").Controls("Address:").text

Now all you need to do is replace B3 with the UNC path of the file.

As an aside, there was also a possibly useful tip (I've not explore
it) at
'spyjournal.biz
(http://www.spyjournal.biz/techtips/2004/10/slashes-in-urls.html)

p45cal
 
H

Heera Chavan

Hi Joel,

Thanks for your reply.
Its not a worksheet function.
My problem is in the following code If ThisWorkbook.Path <> WBPath Then.
the above mentioned code is not working sometimes.

Regards
Heera Chavan
 
H

Heera Chavan

Hi P45cal,

Thank you....your answer was quite near....but I understood cause after
going trough the post.

appriciate your work.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top