B
Bre-x
I would like to transfer the following Excel sub (it works, already test it)
to MS Access. Could you please help me?
Thanks to All
Bre-x
Sub CombineWorkbooks()
Dim bfirst As Boolean, sPath As String
Dim sName As String, bk As Workbook
Dim bk1 As Workbook, sh As Object
bfirst = True
sPath = "N:\1CNCACCESSAPPS\AccessApps\exceltemp\john\"
sName = Dir(sPath & "*.xls")
Do While sName <> ""
Set bk = Workbooks.Open(sPath & sName)
Debug.Print bk.Name
If bfirst Then
bk.Sheets.Copy
bfirst = False
Set bk1 = ActiveWorkbook
Else
bk.Sheets.Copy After:=bk1.Sheets(bk1.Sheets.Count)
End If
bk.Close SaveChanges:=False
sName = Dir()
Loop
Application.DisplayAlerts = False
For Each sh In bk1.Sheets
If InStr(1, sh.Name, "summary", vbTextCompare) Or _
InStr(1, sh.Name, "tic&tie", vbTextCompare) Then
sh.Delete
End If
Next
Application.DisplayAlerts = True
End Sub
My Function on MS Access
----------------------------------------------------
Public Function copy_sheets(tcid As Double, tlid As Double, custid As
String, mach As Integer, prog As Integer)
'Dim string Variables
Dim thepath, bfirst As Boolean, sPath As String, sName As String
Dim bk As Workbook
Dim bk1 As Workbook
Dim sh As Object
'Set Variables
thepath = mypath & mach & "\" & custid & "\" & mach & prog & ".xls"
'Set bk = CreateObject("Excel.Application")
'Set bk1 = CreateObject("Excel.Application")
bfirst = True
sPath = "N:\1CNCACCESSAPPS\AccessApps\exceltemp\john\"
sName = Dir(sPath & "*.xls")
Do While sName <> ""
Set bk = Workbooks.Open(sPath & sName)
Debug.Print bk.Name
If bfirst Then
bk.Sheets.Copy
bfirst = False
Set bk1 = ActiveWorkbook
Else
bk.Sheets.Copy After:=bk1.Sheets(bk1.Sheets.Count)
End If
bk.Close SaveChanges:=False
sName = Dir()
Loop
With bk1.Application
..Visible = True
..DisplayAlerts = False
For Each sh In .Sheets
If InStr(1, sh.Name, "summary", vbTextCompare) Or _
InStr(1, sh.Name, "tic&tie", vbTextCompare) Then
sh.Delete
End If
Next
.DisplayAlerts = True
End With
End Function
to MS Access. Could you please help me?
Thanks to All
Bre-x
Sub CombineWorkbooks()
Dim bfirst As Boolean, sPath As String
Dim sName As String, bk As Workbook
Dim bk1 As Workbook, sh As Object
bfirst = True
sPath = "N:\1CNCACCESSAPPS\AccessApps\exceltemp\john\"
sName = Dir(sPath & "*.xls")
Do While sName <> ""
Set bk = Workbooks.Open(sPath & sName)
Debug.Print bk.Name
If bfirst Then
bk.Sheets.Copy
bfirst = False
Set bk1 = ActiveWorkbook
Else
bk.Sheets.Copy After:=bk1.Sheets(bk1.Sheets.Count)
End If
bk.Close SaveChanges:=False
sName = Dir()
Loop
Application.DisplayAlerts = False
For Each sh In bk1.Sheets
If InStr(1, sh.Name, "summary", vbTextCompare) Or _
InStr(1, sh.Name, "tic&tie", vbTextCompare) Then
sh.Delete
End If
Next
Application.DisplayAlerts = True
End Sub
My Function on MS Access
----------------------------------------------------
Public Function copy_sheets(tcid As Double, tlid As Double, custid As
String, mach As Integer, prog As Integer)
'Dim string Variables
Dim thepath, bfirst As Boolean, sPath As String, sName As String
Dim bk As Workbook
Dim bk1 As Workbook
Dim sh As Object
'Set Variables
thepath = mypath & mach & "\" & custid & "\" & mach & prog & ".xls"
'Set bk = CreateObject("Excel.Application")
'Set bk1 = CreateObject("Excel.Application")
bfirst = True
sPath = "N:\1CNCACCESSAPPS\AccessApps\exceltemp\john\"
sName = Dir(sPath & "*.xls")
Do While sName <> ""
Set bk = Workbooks.Open(sPath & sName)
Debug.Print bk.Name
If bfirst Then
bk.Sheets.Copy
bfirst = False
Set bk1 = ActiveWorkbook
Else
bk.Sheets.Copy After:=bk1.Sheets(bk1.Sheets.Count)
End If
bk.Close SaveChanges:=False
sName = Dir()
Loop
With bk1.Application
..Visible = True
..DisplayAlerts = False
For Each sh In .Sheets
If InStr(1, sh.Name, "summary", vbTextCompare) Or _
InStr(1, sh.Name, "tic&tie", vbTextCompare) Then
sh.Delete
End If
Next
.DisplayAlerts = True
End With
End Function