Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All!

I am trying to write an application simply to edit and reference information from an Excel chart on a shared drive at my workplace. I tested my code on attempting to reference the chart from my C:\ drive and it worked perfectly fine, however when I place it on the shared drive, VB tells me that the file path does not exist. Do I need to add some sort of permission or intent in order to access this drive? My application simply references an excel chart. I can show code if necessary, I have a feeling that this is a simple issue that Im not understanding/...

VB
refSheet = "C:\newtestBook" '' Location of the excel file

Dim completed As Boolean = False
Dim testSheet As New Excel.Application
testSheet.Workbooks.Open(refSheet)
testSheet.Sheets("sheet1").activate()
testSheet.Range("A1").Activate()

When I alter this to be on the shared drive. it tells me that the file path is invalid, it is simply S:\newtestBook and it's not working...

Any suggestions?
Posted
Updated 20-Jun-12 9:42am
v2

1 solution

Yes, check the permissions to the shared folder. You need to be able to read/write into it. If the shared folder is inaccessible (not connected), you can't read the excel file.

VB.NET, VB or VBA?

VB.NET
VB
Dim sFileName = "S:\newtestBook.xls"
Dim exApp As Excel.Application = Nothing
Dim exBook As Excel.Workbook = Nothing
Dim exSheet as Excel.Sheet = Nothing
dim exRange = Excel.Range = Nothing

Try
    exApp = New Excel.Application
    exBook = exApp.Workbooks.Open(sFileName)
    exSheet = exBook.Worksheets("Sheet1")
    exRange = exSheet.Range("A1")

    exRange = "Welcome"
    Msgbox (exSheet.Range("A1").Text)
Catch ex As Exception
    MsgBox (ex.Message, Exclamation, "Error...")
Finally
    'to do: free the memory reserved for variables
End Try


VBA/VB
VB
'need reference to the MS Excel...
Dim sFileName = "S:\newtestBook.xls"
Dim exApp As Excel.Application
Dim exBook As Excel.Workbook
Dim exSheet as Excel.Sheet
dim exRange = Excel.Range

On Error Goto Err_Handler
    Set exApp = New Excel.Application 
    Set exBook = exApp.Workbooks.Open(sFileName)
    Set exSheet = exBook.Worksheets("Sheet1")
    Set exRange = exSheet.Range("A1")

    exRange = "Welcome"
    Msgbox (exSheet.Range("A1").Text)

Exit_Handler:
    On Error Resume Next
    'to do: free the memory reserved for variables
    Exit sub

Err_Handler:
    MsgBox (Err.Description, vbExclamation, Err.Number)
    Resume Exit_Handler
End Try
 
Share this answer
 
Comments
Manas Bhardwaj 21-Jun-12 4:41am    
good +5
Maciej Los 21-Jun-12 7:38am    
Thank you, Manas ;)
MrEng 21-Jun-12 9:51am    
Thank you very much! This helped me and I also talked to our networking tech and he helped me, I wasnt referencing the directories properly, thanks again for all of your help!
Maciej Los 21-Jun-12 16:48pm    
Welcome ;)
If your problem is solved, please mark this question as "solved".
Sandeep Mewara 21-Jun-12 16:37pm    
5+!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900