#1   Report Post  
Dolphinv4
 
Posts: n/a
Default Activate Workbook

Hi,

I have a macro in workbook "AP.xls" that (1) save a backup copy then (2)
open other workbooks as follows:

Dim myDate As String
Dim myFileName As String

myDate = Format(Date, "yymmdd")
myFileName = "C:\" & myDate & " Main.xls"
ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal

Workbooks.Open Filename:="C:\1.xls"
Workbooks.Open Filename:="C:\2.xls"

THEN i want to activate the newly saved workbook again by adding the
following code, but it doesn't work. Why?

ActiveWorkbook.Activate Filename:=myFileName, FileFormat:=xlWorkbookNormal

Regards,
Dolphin
  #2   Report Post  
Dolphinv4
 
Posts: n/a
Default Activate Workbook

i tried to do this, but it still can't work. There is an error.

Sub test()

Dim myDate As String
Dim myFileName As String

myDate = Format(Date, "yymmdd")
myFileName = "C:\" & myDate & " Main.xls"
ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal


Workbooks.Open Filename:="C:\1.xls"


Workbooks(myFileName).Activate

End Sub

"Dolphinv4" wrote:

Hi,

I have a macro in workbook "AP.xls" that (1) save a backup copy then (2)
open other workbooks as follows:

Dim myDate As String
Dim myFileName As String

myDate = Format(Date, "yymmdd")
myFileName = "C:\" & myDate & " Main.xls"
ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal

Workbooks.Open Filename:="C:\1.xls"
Workbooks.Open Filename:="C:\2.xls"

THEN i want to activate the newly saved workbook again by adding the
following code, but it doesn't work. Why?

ActiveWorkbook.Activate Filename:=myFileName, FileFormat:=xlWorkbookNormal

Regards,
Dolphin

  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default Activate Workbook

You don't include the drive and path in this line:

Workbooks(myFileName).Activate

You could use something like:

option Explicit
sub test2()

dim JustFileName as string
dim myFileName as string
dim myDate as string

mydate = format(date,"yymmdd")
justfilename = "mydate & " main.xls"
myfilename = "C:\" & justfilename

ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal
Workbooks.Open Filename:="C:\1.xls"
Workbooks(justfilename).Activate

End sub
=======
Or something like:

Option Explicit
Sub test()

dim wkbk as workbook
Dim myDate As String
Dim myFileName As String

myDate = Format(Date, "yymmdd")
myFileName = "C:\" & myDate & " Main.xls"
ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal
set wkbk = activeworkbook

Workbooks.Open Filename:="C:\1.xls"
wkbk.Activate

End Sub

===============
And as a note, you may want to look at .SaveCopyAs in VBA's help. You can save
a copy of the workbook as a new name--that workbook is a snapshot of the way
that workbook looks right then. And the original isn't renamed, so you don't
have to open it again.


Dolphinv4 wrote:

i tried to do this, but it still can't work. There is an error.

Sub test()

Dim myDate As String
Dim myFileName As String

myDate = Format(Date, "yymmdd")
myFileName = "C:\" & myDate & " Main.xls"
ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal


Workbooks.Open Filename:="C:\1.xls"


Workbooks(myFileName).Activate

End Sub

"Dolphinv4" wrote:

Hi,

I have a macro in workbook "AP.xls" that (1) save a backup copy then (2)
open other workbooks as follows:

Dim myDate As String
Dim myFileName As String

myDate = Format(Date, "yymmdd")
myFileName = "C:\" & myDate & " Main.xls"
ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal

Workbooks.Open Filename:="C:\1.xls"
Workbooks.Open Filename:="C:\2.xls"

THEN i want to activate the newly saved workbook again by adding the
following code, but it doesn't work. Why?

ActiveWorkbook.Activate Filename:=myFileName, FileFormat:=xlWorkbookNormal

Regards,
Dolphin


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Activate new workbook with unknown name rt10516 Excel Discussion (Misc queries) 3 August 24th 05 05:40 AM
activate workbook w/unknown name Jim Cottrell Excel Discussion (Misc queries) 2 July 30th 05 12:31 AM
Activate a workbook from a selection GregR Excel Discussion (Misc queries) 1 April 7th 05 03:25 AM
Unprotect Workbook Kent Excel Discussion (Misc queries) 1 February 4th 05 01:07 AM
Stubborn toolbars in Excel 007 Excel Discussion (Misc queries) 9 December 11th 04 02:02 PM


All times are GMT +1. The time now is 05:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"