R
RompStar
Ok, trying to build a script so that I can automatically as much as I
can import other excel files over the local //network/ to my local PC,
and I got it to work, if I specify the file name directly, but since
the file names changes on a daily basis, I wanted to have a pop-up box
so that I can tell excel what the file name is, since path\\ is alwayds
the same, but I am not sure if the InputBox resurns the value to sNew,
what am I doing wrong ?
Please, help...
---- start here script
Option Explicit
Sub appendfileovernetwork()
Dim networkPath As String
Dim sNew As String
' networkpath represents network \\PATH, always the same
networkPath = "\\network\path
' filename changes daily, file_4-1-2005.xls, file_4-2-2005.xls
' everyday it's different date, use pop-up box to ask for file name
' fileName = "*.xls"
On Error GoTo ERR_DISK
' Open WorkBook over network
Workbooks.Open fileName:=networkPath & sNew
' copy and paste
Workbooks(sNew).Names("Pick_Ups").RefersToRange.Copy _
ThisWorkbook.Worksheets("Import").Range("A65536").End(xlUp).Offset(1,
0)
' close network workbook
Workbooks(sNew).Close
Exit Sub
ERR_DISK:
If Err.Number = 1004 Then
sNew = InputBox("Can not open Excel file, please enter new file name:")
If sNew <> "" Then
Resume
Else
Exit Sub
End If
End If
End Sub
can import other excel files over the local //network/ to my local PC,
and I got it to work, if I specify the file name directly, but since
the file names changes on a daily basis, I wanted to have a pop-up box
so that I can tell excel what the file name is, since path\\ is alwayds
the same, but I am not sure if the InputBox resurns the value to sNew,
what am I doing wrong ?
Please, help...
---- start here script
Option Explicit
Sub appendfileovernetwork()
Dim networkPath As String
Dim sNew As String
' networkpath represents network \\PATH, always the same
networkPath = "\\network\path
' filename changes daily, file_4-1-2005.xls, file_4-2-2005.xls
' everyday it's different date, use pop-up box to ask for file name
' fileName = "*.xls"
On Error GoTo ERR_DISK
' Open WorkBook over network
Workbooks.Open fileName:=networkPath & sNew
' copy and paste
Workbooks(sNew).Names("Pick_Ups").RefersToRange.Copy _
ThisWorkbook.Worksheets("Import").Range("A65536").End(xlUp).Offset(1,
0)
' close network workbook
Workbooks(sNew).Close
Exit Sub
ERR_DISK:
If Err.Number = 1004 Then
sNew = InputBox("Can not open Excel file, please enter new file name:")
If sNew <> "" Then
Resume
Else
Exit Sub
End If
End If
End Sub