rmsapanza
12-06-2007, 03:20 PM
Hi All,
I have a question regarding importing Excel worksheets in workbooks. The code below is what I am using to import the only worksheet in all workbooks in a folder. However, I also need to import all the worksheet tabs in a workbook. How do I modify this code to import all the tabs of a workbook and then move on to the next file? Thanks in advance for any help.
Code
*******************************************************
Private Sub Command0_Click()
On Error GoTo bImportFiles_Click_Err
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String
Dim mCountFiles As Integer
mCountFiles = 0
strFolderPath = "C:\ToImport\"
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strFolderPath)
Set objFiles = objFolder.files
For Each objF1 In objFiles
If Right(objF1.Name, 3) = "xls" Then
mCountFiles = mCountFiles + 1
DoCmd.TransferSpreadsheet acImport, 8, "tblMiwon", strFolderPath & objF1.Name, True, "A4:AO3000"
Name strFolderPath & objF1.Name As "C:\Archived\" & objF1.Name
'Move the files to the archive folder
End If
Next objF1
Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing
If mCountFiles = 0 Then
MsgBox "There Were No files in the Import Folder", vbInformation, "Help ???"
Else
MsgBox mCountFiles & " Files Have Been Imported!!", vbInformation, "All Done!"
End If
bImportFiles_Click_Exit:
Exit Sub
bImportFiles_Click_Err:
Resume bImportFiles_Click_Exit
End Sub
*******************************************************
I have a question regarding importing Excel worksheets in workbooks. The code below is what I am using to import the only worksheet in all workbooks in a folder. However, I also need to import all the worksheet tabs in a workbook. How do I modify this code to import all the tabs of a workbook and then move on to the next file? Thanks in advance for any help.
Code
*******************************************************
Private Sub Command0_Click()
On Error GoTo bImportFiles_Click_Err
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String
Dim mCountFiles As Integer
mCountFiles = 0
strFolderPath = "C:\ToImport\"
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strFolderPath)
Set objFiles = objFolder.files
For Each objF1 In objFiles
If Right(objF1.Name, 3) = "xls" Then
mCountFiles = mCountFiles + 1
DoCmd.TransferSpreadsheet acImport, 8, "tblMiwon", strFolderPath & objF1.Name, True, "A4:AO3000"
Name strFolderPath & objF1.Name As "C:\Archived\" & objF1.Name
'Move the files to the archive folder
End If
Next objF1
Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing
If mCountFiles = 0 Then
MsgBox "There Were No files in the Import Folder", vbInformation, "Help ???"
Else
MsgBox mCountFiles & " Files Have Been Imported!!", vbInformation, "All Done!"
End If
bImportFiles_Click_Exit:
Exit Sub
bImportFiles_Click_Err:
Resume bImportFiles_Click_Exit
End Sub
*******************************************************