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

Hi
I have a workbook that I have set workbook names but for some reason I keep
getting a runtime error 9.

I have attached the code which I have, could someone let me know what I have
done or missed out.

Dim wbkCurrent, wbkNew As Workbook

Set wbkCurrent = Workbooks("Stock Adjustment Workbook.xls")

The error keeps occuring at the set line.

Thanks
Noemi
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Runtime Error 9

A couple of things to note. You have declared your object variables a little
bit wrong. It should be...

Dim wbkCurrent as workbook
dim wbkNew As Workbook

otherwise you are actually declaring wbkCurrent as type variant (check out
this web site http://www.cpearson.com/excel/variables.htm)

The other issue with your code is that if the workbook is not open then the
code will crash (this is most likely the problem causing your error). Give
this a try...

Dim wbkCurrent as workbook
dim wbkNew As Workbook

On Error Resume Next
Set wbkCurrent = Workbooks("Stock Adjustment Workbook.xls")
on Error goto 0

if wbkcurrent is nothing then _
Set wbkCurrent = Workbooks.Open("C:\Stock Adjustment Workbook.xls")

--
HTH...

Jim Thomlinson


"Noemi" wrote:

Hi
I have a workbook that I have set workbook names but for some reason I keep
getting a runtime error 9.

I have attached the code which I have, could someone let me know what I have
done or missed out.

Dim wbkCurrent, wbkNew As Workbook

Set wbkCurrent = Workbooks("Stock Adjustment Workbook.xls")

The error keeps occuring at the set line.

Thanks
Noemi

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Runtime Error 9

Thanks Jim

"Jim Thomlinson" wrote:

A couple of things to note. You have declared your object variables a little
bit wrong. It should be...

Dim wbkCurrent as workbook
dim wbkNew As Workbook

otherwise you are actually declaring wbkCurrent as type variant (check out
this web site http://www.cpearson.com/excel/variables.htm)

The other issue with your code is that if the workbook is not open then the
code will crash (this is most likely the problem causing your error). Give
this a try...

Dim wbkCurrent as workbook
dim wbkNew As Workbook

On Error Resume Next
Set wbkCurrent = Workbooks("Stock Adjustment Workbook.xls")
on Error goto 0

if wbkcurrent is nothing then _
Set wbkCurrent = Workbooks.Open("C:\Stock Adjustment Workbook.xls")

--
HTH...

Jim Thomlinson


"Noemi" wrote:

Hi
I have a workbook that I have set workbook names but for some reason I keep
getting a runtime error 9.

I have attached the code which I have, could someone let me know what I have
done or missed out.

Dim wbkCurrent, wbkNew As Workbook

Set wbkCurrent = Workbooks("Stock Adjustment Workbook.xls")

The error keeps occuring at the set line.

Thanks
Noemi

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
xpath error? Runtime Error 13 type mismatch Steve M[_2_] Excel Discussion (Misc queries) 0 January 17th 08 01:16 AM
xpath error? Runtime Error 13 type mismatch SteveM Excel Discussion (Misc queries) 1 December 4th 07 09:16 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Syntax Error Runtime Error '424' Object Required sjenks183 Excel Programming 1 January 23rd 04 09:25 AM
Unknown where is the problem on the Runtime error - Automation error wellie Excel Programming 1 July 10th 03 08:12 AM


All times are GMT +1. The time now is 06:32 PM.

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"