Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 39
Default string assistance to open workbook via macro

I have the following macro:

Sub Macro2()

Dim datestamp As String
Dim link As String
datestamp = Format(Date, "yyyy_mm_dd")
link = "Arrestments Planning Model " & datestamp & ".xls"

ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets("Centre Summary Plan").Select
Range("E5").Select
Windows("Planning Model.xls").Activate
Windows(link).Activate
Application.Run _
"'link'!Plan_Weekly_Summary"
Range("E39").Select
Windows("Planning Model.xls").Activate
ActiveCell.FormulaR1C1 = _
"='[link]Summary Plan'!R26C4"
Range("E6").Select
ActiveCell.FormulaR1C1 = _
"='[link]Summary Plan'!R28C4"
Range("E5").Select
End Sub

The dim link is showing the correct file name but the code debugs at
Windows(link).Activate.

Can anyone help?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default string assistance to open workbook via macro

Is the workbook already open??? You need to open a workbook before you can
activate it. Try something more like this...

Sub Macro2()
dim wbkTarget as workbook
Dim datestamp As String
Dim link As String
datestamp = Format(Date, "yyyy_mm_dd")
link = "Arrestments Planning Model " & datestamp & ".xls"

ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets("Centre Summary Plan").Select
Range("E5").Select
Windows("Planning Model.xls").Activate
on error resume next
set wbktarget = workbooks(link)
if wbktarget is nothing then
set wbktarget = workbooks.open("C:\" & link) 'modify directory
if wbktarget is nothing then
msgbox "Sorry can't find " & link
exit sub
end if
on error goto 0

Windows(link).Activate
Application.Run _
"'link'!Plan_Weekly_Summary"
Range("E39").Select
Windows("Planning Model.xls").Activate
ActiveCell.FormulaR1C1 = _
"='[link]Summary Plan'!R26C4"
Range("E6").Select
ActiveCell.FormulaR1C1 = _
"='[link]Summary Plan'!R28C4"
Range("E5").Select
End Sub

--
HTH...

Jim Thomlinson


"fishy" wrote:

I have the following macro:

Sub Macro2()

Dim datestamp As String
Dim link As String
datestamp = Format(Date, "yyyy_mm_dd")
link = "Arrestments Planning Model " & datestamp & ".xls"

ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets("Centre Summary Plan").Select
Range("E5").Select
Windows("Planning Model.xls").Activate
Windows(link).Activate
Application.Run _
"'link'!Plan_Weekly_Summary"
Range("E39").Select
Windows("Planning Model.xls").Activate
ActiveCell.FormulaR1C1 = _
"='[link]Summary Plan'!R26C4"
Range("E6").Select
ActiveCell.FormulaR1C1 = _
"='[link]Summary Plan'!R28C4"
Range("E5").Select
End Sub

The dim link is showing the correct file name but the code debugs at
Windows(link).Activate.

Can anyone help?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 39
Default string assistance to open workbook via macro

It seems to debug at the Windows(link).activate

"Jim Thomlinson" wrote:

Is the workbook already open??? You need to open a workbook before you can
activate it. Try something more like this...

Sub Macro2()
dim wbkTarget as workbook
Dim datestamp As String
Dim link As String
datestamp = Format(Date, "yyyy_mm_dd")
link = "Arrestments Planning Model " & datestamp & ".xls"

ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets("Centre Summary Plan").Select
Range("E5").Select
Windows("Planning Model.xls").Activate
on error resume next
set wbktarget = workbooks(link)
if wbktarget is nothing then
set wbktarget = workbooks.open("C:\" & link) 'modify directory
if wbktarget is nothing then
msgbox "Sorry can't find " & link
exit sub
end if
on error goto 0

Windows(link).Activate
Application.Run _
"'link'!Plan_Weekly_Summary"
Range("E39").Select
Windows("Planning Model.xls").Activate
ActiveCell.FormulaR1C1 = _
"='[link]Summary Plan'!R26C4"
Range("E6").Select
ActiveCell.FormulaR1C1 = _
"='[link]Summary Plan'!R28C4"
Range("E5").Select
End Sub

--
HTH...

Jim Thomlinson


"fishy" wrote:

I have the following macro:

Sub Macro2()

Dim datestamp As String
Dim link As String
datestamp = Format(Date, "yyyy_mm_dd")
link = "Arrestments Planning Model " & datestamp & ".xls"

ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets("Centre Summary Plan").Select
Range("E5").Select
Windows("Planning Model.xls").Activate
Windows(link).Activate
Application.Run _
"'link'!Plan_Weekly_Summary"
Range("E39").Select
Windows("Planning Model.xls").Activate
ActiveCell.FormulaR1C1 = _
"='[link]Summary Plan'!R26C4"
Range("E6").Select
ActiveCell.FormulaR1C1 = _
"='[link]Summary Plan'!R28C4"
Range("E5").Select
End Sub

The dim link is showing the correct file name but the code debugs at
Windows(link).Activate.

Can anyone help?

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
Macro in 2nd Open workbook Steve Excel Discussion (Misc queries) 1 January 28th 08 06:35 PM
Open Workbook Macro??? Supe Excel Discussion (Misc queries) 2 December 19th 07 09:37 PM
Run a macro when I open a workbook CraigJ Excel Discussion (Misc queries) 1 June 13th 07 05:04 PM
Macro to open most recent file with a particular filename string kwiklearner Excel Discussion (Misc queries) 1 August 23rd 06 02:24 AM
How to Run Macro in open workbook/s hni Excel Discussion (Misc queries) 1 October 31st 05 11:14 AM


All times are GMT +1. The time now is 07:36 AM.

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"