Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 259
Default Error Opening Workbook

Hi All

I have been using this code for some time, the only difference today is that
I decided to move this particular code from 1 module to another.

And now it's throwing up an error at the start of this line:

FileToOpen

Variable not Defined


Sub ImportSchedData()

Dim SDataWb As Workbook, TDataWb As Workbook

ChDrive "T:\"
ChDir "T:\VIC\Scheduler"

FileToOpen = Application.GetOpenFilename _
(Title:="Select a TMS File to Import", _
FileFilter:="Excel Files *.xls (*.xls),")

If FileToOpen = False Then
MsgBox "No file specified.", vbExclamation, "Doh!!!"
Exit Sub
Else
Workbooks.Open Filename:=FileToOpen
End If

Set SDataWb = Workbooks.Open(Filename:=FileToOpen)
Set TDataWb = Workbooks("VicMaster.xls")

SDataWb.Sheets("Main").Range("A2:Q500").Copy

Windows("VicMaster.xls").Activate
Sheets("Master").Select
Range("A5").Select
ActiveSheet.Paste
Application.CutCopyMode = False

SDataWb.Close noSave

End Sub

II spent an hour on it trying different things, and it's got me beat.

Any thoughts
TIA
Mick.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Error Opening Workbook

Vacuum Sealed wrote on 7/6/2011 :
Hi All

I have been using this code for some time, the only difference today is that
I decided to move this particular code from 1 module to another.

And now it's throwing up an error at the start of this line:

FileToOpen

Variable not Defined


Sub ImportSchedData()

Dim SDataWb As Workbook, TDataWb As Workbook

ChDrive "T:\"
ChDir "T:\VIC\Scheduler"

FileToOpen = Application.GetOpenFilename _
(Title:="Select a TMS File to Import", _
FileFilter:="Excel Files *.xls (*.xls),")

If FileToOpen = False Then
MsgBox "No file specified.", vbExclamation, "Doh!!!"
Exit Sub
Else
Workbooks.Open Filename:=FileToOpen
End If

Set SDataWb = Workbooks.Open(Filename:=FileToOpen)
Set TDataWb = Workbooks("VicMaster.xls")

SDataWb.Sheets("Main").Range("A2:Q500").Copy

Windows("VicMaster.xls").Activate
Sheets("Master").Select
Range("A5").Select
ActiveSheet.Paste
Application.CutCopyMode = False

SDataWb.Close noSave

End Sub

II spent an hour on it trying different things, and it's got me beat.

Any thoughts
TIA
Mick.


Dim FileToOpen As String???

I suspect you do have Option Explicit declared at the top of the module
and so VBA is looking for your definition of FileToOpen.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 259
Default Error Opening Workbook

Thx Garry

Interestingly, never had it declared.

I use the exact same code (with the exception of the last three lines which
activate the source WB lastly, then closes it) in a different workbook,
again undeclared and it works problem free.

I tried your answer way before I posted this thread, I even tried Dimming it
as a variant.

As it is at work, I will have a go at with the declaration angle this time
and see what happens.

As work does not allow Newsgroups, I cannot access any responses til I get
home in roughly 12 hours.

Cheers
Mick.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 259
Default Error Opening Workbook

Hi Garry

I did some more moving of codes again.

I move this particular code into it's own module and wollah..!!

Working as if nothing was ever wrong with it.

I did declare it, but then I had a follow-on issue where it stating that the
Object or Variable = nothing.

I removed the declaration and compiled it again and it works fine.

I have no idea, and will leave it at that and make sure for future reference
to never mix routines of this nature in the same module.

Cheers & thx again
Mick.


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
Error while opening workbook Anand Nichkaode Excel Discussion (Misc queries) 0 June 14th 08 03:18 PM
error opening a workbook budi1568 Excel Programming 3 January 27th 08 05:13 AM
error when opening a workbook Jamie Excel Programming 0 November 7th 07 05:50 PM
Error on opening more than one workbook containing the same code [email protected] Excel Programming 0 December 14th 06 12:25 PM
Error in opening workbook [email protected] Excel Programming 7 October 17th 06 04:34 PM


All times are GMT +1. The time now is 01:50 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"