Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / April 2008

Tip: Looking for answers? Try searching our database.

Mqcro loop / password code /

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Snoopy - 28 Apr 2008 11:45 GMT
Hey guys
I've made a summary-file to collect data from several files in a
commen folder.
So far I've hardcoded my macro to pick up the datas from every singel-
named file.
The same prosedyre is used on every singel file.
This must be wiser to perform this by using a loop-statement...but
how?
There are 9 separate files to handle (I show my reference to the 2 of
them)
Some of the files may be protected by password.
Are there any way to "tell" the macro to still open it?
When running my primitiv macro a messagebox pops up and say there is a
lot of copyed data on the clipboard. I want the macro to run through
the lot whithout stopping.
How do I do this?

I will be very thankfull for your help

Regards
Snoopy

The tricky part of my macro:

'Merk "Petter - protected file - opens with password: "123"
Application.StatusBar = "Petter"
   Workbooks.Open Filename:="E:\Petter.xls"

   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("Rapport.xls").Activate

   Sheets("Samlet").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("Petter.xls").Activate
   ActiveWindow.Close

'Merk "Rita"
Application.StatusBar = "Rita"
   Workbooks.Open Filename:="E:\Rita.xls"

   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("Rapport.xls").Activate

   Sheets("Samlet").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("Rita.xls").Activate
   ActiveWindow.Close

'Merk "Sidsel"
Application.StatusBar = "Sidsel"
   Workbooks.Open Filename:="E:\sidsel.xls"

   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("Rapport.xls").Activate

   Sheets("Samlet").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("sidsel.xls").Activate
   ActiveWindow.Close
Earl Kiosterud - 28 Apr 2008 14:44 GMT
Snoop,

There's a lot of code in your post that has nothing to do with your questions, but I think
this is what you're after:

Dim i As Integer

Dim MyFiles(2)  ' three files, 0-2
Dim MyPasswords(2) ' could have been a single 2-dimensional array for both

' Load up file names
MyFiles(0) = "a.xls"
MyFiles(1) = "b.xls"
MyFiles(2) = "c.xls"

' Load up passwords
MyPasswords(0) = "ab"
MyPasswords(1) = ""   ' (not password protected)
MyPasswords(2) = ""

For i = 0 To (UBound(MyFiles))  '  Start looping through the workbooks
 Workbooks.Open Filename:=MyFiles(i), ReadOnly:=True, Password:=MyPasswords(i)

 ' Do your stuff here

 ' Close the file
 Application.CutCopyMode = False ' prevent message about clipboard
 ActiveWorkbook.Close SaveChanges:=False
 Next i
End Sub

Signature

Regards from Virginia Beach,

Earl Kiosterud
www.smokeylake.com
-----------------------------------------------------------------------

> Hey guys
> I've made a summary-file to collect data from several files in a
[quoted text clipped - 115 lines]
>    Windows("sidsel.xls").Activate
>    ActiveWindow.Close
Snoopy - 29 Apr 2008 07:58 GMT
> Snoop,
>
[quoted text clipped - 153 lines]
>
> – Vis sitert tekst –

Thanks a lot :)))

Best regards
Snoopy
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.