Dear Yuan,
thanks for your codes and guidance. It has really helped a lot and saved a lot of time.
Really appreciated.
Thanks a ton
Cheers !!!
@norman.yuan wrote:
There are a lot sample code you can find if you google the net for Excel automation. Here is some quick code off my head without actual test:
Public Sub SaveNewDrawings()
Dim fileNames as Variant
Dim folder As String
Dim i As Integer
folder="C:\MyDrawings\"
fileNames = GetFileNamesFromExcelSheet("C:\MyDrawings\MyFileList.xlsx")
If Ubound(fileNames)<0 Then Exit Sub
For i=0 to Ubound(fileNames)
ThisDrawing.SaveAs folder & fileNames(i)
Next
End Sub
Private Function GetFileNamesFromExcelSheet(sheehFile As String) As Variant
Dim fNames() As String
Dim fName As String
Dim i As Integer
Dim xlsApp As Excel.Application
Dim sheet As Worksheet
Dim excelStarted As Boolean
On Error Resume Next
Set xlsApp=GetObject( , "Excel.Application")
If Err.Number<>0 Then
Err.Clear
Set xlsApp=CreateObject("Excel.Application")
excelStarted = True
Enhd If
On Error Goto 0
If xlsApp Is Nothing Then
MsgBox "Cannot open Excel application!"
Else
xlsApp.Workbooks.Open sheetFile
'' Assume the active sheet is the sheet containing the data (A1 to A15)
'' otherwise you need to identify which sheet to read the data
For i=0 to 14
fName=CStr(ActiveSheet.Range("A" & i+1).Value)
ReDim Preserve fNames(i)
fNames(i)=fName
Next
End If
If excelStarted then xlsApp.Quit
GetFileNamesFromExcelSheet=fNames
End Function
Again, the code is not tested. Just give you an idea.
HTH
@norman.yuan wrote:
There are a lot sample code you can find if you google the net for Excel automation. Here is some quick code off my head without actual test:
Public Sub SaveNewDrawings()
Dim fileNames as Variant
Dim folder As String
Dim i As Integer
folder="C:\MyDrawings\"
fileNames = GetFileNamesFromExcelSheet("C:\MyDrawings\MyFileList.xlsx")
If Ubound(fileNames)<0 Then Exit Sub
For i=0 to Ubound(fileNames)
ThisDrawing.SaveAs folder & fileNames(i)
Next
End Sub
Private Function GetFileNamesFromExcelSheet(sheehFile As String) As Variant
Dim fNames() As String
Dim fName As String
Dim i As Integer
Dim xlsApp As Excel.Application
Dim sheet As Worksheet
Dim excelStarted As Boolean
On Error Resume Next
Set xlsApp=GetObject( , "Excel.Application")
If Err.Number<>0 Then
Err.Clear
Set xlsApp=CreateObject("Excel.Application")
excelStarted = True
Enhd If
On Error Goto 0
If xlsApp Is Nothing Then
MsgBox "Cannot open Excel application!"
Else
xlsApp.Workbooks.Open sheetFile
'' Assume the active sheet is the sheet containing the data (A1 to A15)
'' otherwise you need to identify which sheet to read the data
For i=0 to 14
fName=CStr(ActiveSheet.Range("A" & i+1).Value)
ReDim Preserve fNames(i)
fNames(i)=fName
Next
End If
If excelStarted then xlsApp.Quit
GetFileNamesFromExcelSheet=fNames
End Function
Again, the code is not tested. Just give you an idea.
HTH