0
votes

I have encountered a problem regarding the workbook.open function, when trying to open a workbook located on a network folder. The VBA macro leeds to an

"1004 Error"

without any specific reasons, only that the file path is not available.

I have used Google and this community for a very long time to solve this issue, below my steps I tried and my only solution at the end. My question is: WHY does Excel behave like that and what can I do the next time?

  • Initially the user inputs the file path in a cell within the Source Workbook, saved locally on the computer. The VBA code take the input of the cell (I tried Range("K4") and also Range("K4").value) and aligns it to the string, which is visible (Variable Watch while Debugging) but failes when it comes to the Workbook.open function.

  • I tried to use the user specific network path (e.g. "G:/...") but also the Universal Network convention path ("\\xxx.xxx...") which is more accurate because not every user has mapped the network folder to the same drive letter.

  • At the end my only working solution was the hard coded path in the VBA editor with the UNC path.

Why is so? In this case the networkpath does not change, but when it comes to the moment where it is necessary that the folder must be written in a cell I will be lost.

Thank you for your feebdack!

EDIT: Basically it's this code... I removed the unnecessary parts...

'Variablen
Dim MA$, Monat$, Fehltag$, Ort$, Projekt$, FilePlanung$, MainString$, NeuerString$
Dim LastRowM&, StartZelleP&, ProjektP&
Dim wb, wbP As Workbook
Dim wsK, wsS, wsM As Worksheet
Dim StartDatumM As Date
Dim array_monate As Variant

'Arbeitsblätter
Set wb = ThisWorkbook
Set wsK = wb.Sheets("Kopfblatt")
Set wsS = wb.Sheets("Stammdaten")
Set wsM = wb.ActiveSheet

'Fix
MA = wsK.Range("D2")
Monat = wsM.Name
FilePlanung = wsS.Range("K4")

Application.ScreenUpdating = False
Set wbP = Workbooks.Open(fileName:=FilePlanung)
'Set wbP = Workbooks.Open(FilePlanung) --> Tried also this and many other ways...
Set wsP = wbP.Sheets("aktuell")
1
Opening an excel file from a unc path works fine for me. Also when grabbing the path from a cell. - gizlmo
@gizlmo could you please paste the code you use? is it maybe a formatting issue from the cell as well? - smartini

1 Answers

0
votes

This is the code I use:

Dim wb As Workbook

Set wb = Workbooks.Open(Worksheets("Sheet1").Range("A1").Value)