S
Snoopy
Hey guys
Her is my little challenge:
Filename (example):
c:\Aplications\Report\ReportA.xls
- containing a "main macro" opening the files (below) one by one, copy
data from them and paste into the ReportA.xls.
c:\Aplications\Report\user\aaa.xls
c:\Aplications\Report\user\bbb.xls
c:\Aplications\Report\user\ccc.xls
c:\Aplications\Report\user\ddd.xls
etc
Main Macro:
Sub Main ()
' Preparing
Start
'Copying from users
aaa
bbb
ccc
'Calculating and formatting general report
Stop
End sub
My sub usermacros - placed in the main file - open the user files
respectively - named aaa, bbb, ccc, etc
Sub macro:
Sub aaa ()
Application.StatusBar = "Collecting data from aaa"
Dim i As Integer
Dim MyFiles(1)
Dim MyPasswords(1)
MyFiles(1) = "c:\Aplications\Report\ReportA.xls"
MyPasswords(1) = ""
Workbooks.Open Filename:="c:\Aplications\Report\user\aaa.xls",
ReadOnly:=True, Password:=MyPasswords(1), UpdateLinks:=0
Sheets("Register").Visible = True
Sheets("Register").Select
Range("A2").Select
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
Set tbl = ActiveCell.CurrentRegion
tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1, _
tbl.Columns.Count).Select
Selection.Copy
Range("A2").Select
Windows("ReportA.xls").Activate
Sheets("Sample").Select
Selection.Offset(0, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.End(xlDown).Select
Selection.Offset(1, 0).Range("A1").Select
Windows("ReportA.xls").Activate
Application.CutCopyMode = False ' prevent message about clipboard
ActiveWorkbook.Close savechanges:=False
End Sub
So far I have hardcoded the macro to open each file by filename, but
find it difficult to update over time.
I hope to make my macro automaticly run through all files in the Report
\user-folder and do the stuff on each file in a smother way by using
lopps - but I'm stucked.
Anyone that feel the comfort in helping me?
Thankfully regards
Snoopy
Her is my little challenge:
Filename (example):
c:\Aplications\Report\ReportA.xls
- containing a "main macro" opening the files (below) one by one, copy
data from them and paste into the ReportA.xls.
c:\Aplications\Report\user\aaa.xls
c:\Aplications\Report\user\bbb.xls
c:\Aplications\Report\user\ccc.xls
c:\Aplications\Report\user\ddd.xls
etc
Main Macro:
Sub Main ()
' Preparing
Start
'Copying from users
aaa
bbb
ccc
'Calculating and formatting general report
Stop
End sub
My sub usermacros - placed in the main file - open the user files
respectively - named aaa, bbb, ccc, etc
Sub macro:
Sub aaa ()
Application.StatusBar = "Collecting data from aaa"
Dim i As Integer
Dim MyFiles(1)
Dim MyPasswords(1)
MyFiles(1) = "c:\Aplications\Report\ReportA.xls"
MyPasswords(1) = ""
Workbooks.Open Filename:="c:\Aplications\Report\user\aaa.xls",
ReadOnly:=True, Password:=MyPasswords(1), UpdateLinks:=0
Sheets("Register").Visible = True
Sheets("Register").Select
Range("A2").Select
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
Set tbl = ActiveCell.CurrentRegion
tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1, _
tbl.Columns.Count).Select
Selection.Copy
Range("A2").Select
Windows("ReportA.xls").Activate
Sheets("Sample").Select
Selection.Offset(0, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.End(xlDown).Select
Selection.Offset(1, 0).Range("A1").Select
Windows("ReportA.xls").Activate
Application.CutCopyMode = False ' prevent message about clipboard
ActiveWorkbook.Close savechanges:=False
End Sub
So far I have hardcoded the macro to open each file by filename, but
find it difficult to update over time.
I hope to make my macro automaticly run through all files in the Report
\user-folder and do the stuff on each file in a smother way by using
lopps - but I'm stucked.
Anyone that feel the comfort in helping me?
Thankfully regards
Snoopy