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 / October 2004

Tip: Looking for answers? Try searching our database.

A macro question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Kitchens - 01 Oct 2004 15:26 GMT
Hello,

I have a macro that when prompted opens up many different files that are
located in the same folder.

Each of these files that I am opening are files that have been previously
summarized through the use of a macro.

Example: I wll have 40 to 60 files that I save in the same folder on a daily
basis.  At the end of the day I use a template and a macro that will open
all of the daily files and summarize them into one neat sheet for me.  When
this macro is executed all of the 40 to 60 daily files are opened to give me
the total of my daily summary sheet.

I save each of these daily summaries as DS100104.xls etc, tommorrow
DS100204.xls etc.

Now what I have created a new template that will be a weekly, monthly,
quarterly and so forth summary.

I have modified the macro so that it will open page 1 of the DS files. It
works, but I am getting the following message when I open the DS files:

"Microsoft Excel"

"The workbook you opened contains automatic links to information in another
workbook. Do you want to update this workbook with changed made to the other
workbook?"

"To update all linked information, click Yes.
To keep the existing information, click No."

This is a copy of the macro that runs my program:

Sub GetSheets()
Dim i As Long
Dim varr As Variant
Dim wkbk As Workbook
Dim ws As Worksheet
Application.DisplayAlerts = False
varr = Application.GetOpenFilename(filefilter:="Excel Files, *.xls", _
           MultiSelect:=True)
If IsArray(varr) Then
   For i = LBound(varr) To UBound(varr)
     Set wkbk = Workbooks.Open(varr(i))
     Set ws = wkbk.Sheets("Summary")
     ws.Unprotect
     ws.Name = Left(wkbk.Name, Len(wkbk.Name) - 4)
     ws.Cells.Style = "Normal"
     ws.DrawingObjects.Delete
     ws.Copy After:=ThisWorkbook.Worksheets("Start")

     wkbk.Close SaveChanges:=False
   Next
End If
Application.DisplayAlerts = True
End Sub

Sub UnhideSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Sheets
 ws.Visible = xlSheetVisible
Next ws
End Sub

I am hoping that this macro can be modified so that "No" will automatically
be selected for each sheet so that the user doesn't have to click it each
time.

Thanks for any help I can get.

John
Frank Kabel - 01 Oct 2004 17:22 GMT
Hi
have a look in the VBA help for workbooks.open. You can specify the
Updatelink parameter to avoid this message

Signature

--
Regards
Frank Kabel
Frankfurt, Germany


> Hello,
>
[quoted text clipped - 68 lines]
>
> John
John Kitchens - 01 Oct 2004 21:54 GMT
Thanks for the reply Frank. For some reason my help files are missing. Can
you tell me what the command would look like so that I can try it. I am new
to VBA and I can't seem to get this right.

John

> Hi
> have a look in the VBA help for workbooks.open. You can specify the
[quoted text clipped - 91 lines]
> >
> > John
Dave Peterson - 01 Oct 2004 21:31 GMT
If you position your cursor on the .open in workbooks.open(...), then hit F1,
you should see the help for Open.

If this doesn't work--VBA's help isn't installed, I'd rerun Office Setup and
make sure I chose to install VBA's help.

> Thanks for the reply Frank. For some reason my help files are missing. Can
> you tell me what the command would look like so that I can try it. I am new
[quoted text clipped - 97 lines]
> > >
> > > John

Signature

Dave Peterson
ec35720@msn.com

Dave Peterson - 01 Oct 2004 21:09 GMT
Along with what Frank wrote, I'd add a readonly option, too.  If you're just
opening the workbook to copy stuff out of it, you'll be able to open it if
someone else has it open--or if it's marked readonlyrecommended:

Set wkbk = Workbooks.Open(varr(i), UpdateLinks = 0, ReadOnly:=True)

Take a look at help for more info (er, like Frank wrote).

> Hello,
>
[quoted text clipped - 68 lines]
>
> John

Signature

Dave Peterson
ec35720@msn.com

John Kitchens - 05 Oct 2004 14:10 GMT
Hello Dave,

I tried to adding the line that you gave me: Set wkbk =
Workbooks.Open(varr(i), UpdateLinks = 0, ReadOnly:=True)

but it didn't work. Below is a copy of my macro. When I try it I get a
"Compile error:
Variable not defined" message.  I don't know what it is wrong. Do you have
any suggestions.

Thank you for all of your help.

Sincerely,
John Kitchens

Sub GetSheets()
Dim i As Long
Dim varr As Variant
Dim wkbk As Workbook
Dim ws As Worksheet
Application.DisplayAlerts = False
varr = Application.GetOpenFilename(filefilter:="Excel Files, *.xls", _
           MultiSelect:=True)
If IsArray(varr) Then
   For i = LBound(varr) To UBound(varr)
     Set wkbk = Workbooks.Open(varr(i))
     Set ws = wkbk.Sheets("Summary")
     ws.Unprotect
     ws.Name = Left(wkbk.Name, Len(wkbk.Name) - 4)
     ws.Cells.Style = "Normal"
     ws.DrawingObjects.Delete
     ws.Copy After:=ThisWorkbook.Worksheets("Start")

     wkbk.Close SaveChanges:=False
   Next
End If
Application.DisplayAlerts = True
End Sub

Sub UnhideSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Sheets
 ws.Visible = xlSheetVisible
Next ws
End Sub

> Along with what Frank wrote, I'd add a readonly option, too.  If you're just
> opening the workbook to copy stuff out of it, you'll be able to open it if
[quoted text clipped - 81 lines]
> Dave Peterson
> ec35720@msn.com
Dave Peterson - 05 Oct 2004 22:52 GMT
I had a typo in my suggested line:

Set wkbk = Workbooks.Open(varr(i), UpdateLinks:=0, ReadOnly:=True)

Notice the extra colon in updatelinks:=0

Sorry.

> Hello Dave,
>
[quoted text clipped - 138 lines]
> > Dave Peterson
> > ec35720@msn.com

Signature

Dave Peterson
ec35720@msn.com

John Kitchens - 06 Oct 2004 18:51 GMT
Hello Dave,

When I made this latest change it works perfectly! Thank you so much.

I now have another problem I need help with. Should I post here or start a
new thread? (I am not sure of the rules of the forum)

Sincerely,

John Kitchens

> I had a typo in my suggested line:
>
[quoted text clipped - 151 lines]
> Dave Peterson
> ec35720@msn.com
Dave Peterson - 06 Oct 2004 21:40 GMT
Start a new thread.

I think that sometimes posts in existing threads get skipped over (I've been
told that this isn't true by others--but I know that I do it when it looks like
the discussion is going well).

> Hello Dave,
>
[quoted text clipped - 173 lines]
> > Dave Peterson
> > ec35720@msn.com

Signature

Dave Peterson
ec35720@msn.com

 
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.