LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default run time error 9


Hello all

A while back I had to quickly put together a routine to take the
information from a main workbook and copy and save aspects of the data
into many different workbooks using a second workbook as a template. At
the time I recorded a macro to deal with the repetitive stuff which
meant that the workbook names of the workbook containing the data and
the template where embedded in the code. I am trying to tidy it up by
using the code below to specify the main workbook and the template.

Sub GetFilePathCopyTo()

Dim Finfo As String
Dim FilterIndex As Integer
Dim Title As String

' Set up list of file filters
Finfo = "Text Files (*.txt),*.txt," & _
"Lotus Files (*.prn),*.prn," & _
"Comma Separated Files (*.csv),*.csv," & _
"ASCII Files (*.asc),*.asc," & _
"All Files (*.*),*.*"

' Display *.* by default
FilterIndex = 5

' Set the dialog box caption
Title = "Select a File to Copy To"

' Get the filename
FilePathCopyTo = Application.GetOpenFilename(Finfo, _
FilterIndex, Title)

' Handle return info from dialog box
If FilePathCopyTo = False Then
MsgBox "No file was selected."
Else
MsgBox "You selected " & FilePathCopyTo
End If

End Sub


This works fine and I changed the next bit of code in the process from


Sub OpenRequote()

Workbooks.Open Filename:= _
"I:\Costings\Development\2005 - 2006\Requote\requote
template.xls"
Range("B6").Select
Windows("SAStanCosts WE 11 19 05.xls").Activate

End Sub


To this so that the hard coded workbook name was replaced


Sub OpenRequote()

Workbooks.Open FileName:= FilePathCopyTo
Range("B6").Select
Windows(FilePathCopyTo).Activate

End Sub


I am getting a run time error 9 when the code gets to
Windows(FilePathCopyTo).Activate and I don’t know what to do, can
anybody help?

Regards

Adrian


--
SandyUK
------------------------------------------------------------------------
SandyUK's Profile: http://www.excelforum.com/member.php...o&userid=17487
View this thread: http://www.excelforum.com/showthread...hreadid=547362

 
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
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error rdavis7408 Excel Programming 1 August 25th 04 03:54 AM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM
Run-time error '11' & Run-time error '1004' Piers Clinton-Tarestad Excel Programming 0 January 9th 04 07:45 PM


All times are GMT +1. The time now is 05:08 AM.

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

About Us

"It's about Microsoft Excel"