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 "Dim" problem


Hi all I am trying to Dim an object at a module level, this is my code:


Code
-------------------
Dim Main_wb As Workbook

Sub ImportFiles()

' Record the main workbook
Set Main_wb = ActiveWorkbook

'more code blah blah

ws_index = Find_Sheet(Sheet_Name)
End Sub

Function Find_Sheet(s_name As String) As Integer
' Will check the workbook for a sheet for this name;
' If found returns the worksheets index, if not found inserts it and returns index
Dim ws_index As Integer

' Cycle through the sheets
With Main_wb
MsgBox .Worksheets.Count ' <==== HERE
For ws_index = 0 To .Worksheets.Count
If .Worksheets(ws_index).name = s_name Then
Find_Sheet = ws_index
Exit Function
End If
Next
.Worksheets.Add Befo=.Worksheets(1)
.Worksheets(1).name = s_name
End With
End Functio
-------------------


However on the line marked "<=== HERE" I get an automation error.
When I checked using the watch window my Main_wb object doesn't seem t
contain anything at this point but when running through the main sub i
does.

I thought by "Dim"ing it outside of any sub or function it would b
available to all?

What have I done wrong?

Thanks,

Phi

--
Phil_
-----------------------------------------------------------------------
Phil_V's Profile: http://www.excelforum.com/member.php...fo&userid=3185
View this thread: http://www.excelforum.com/showthread.php?threadid=52337

 
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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
problem with Linking workbooks via "copy" and "paste link" Arkitek Excel Discussion (Misc queries) 0 December 19th 06 10:03 PM
Problem: Worksheets("New Style 2006").Unprotect Password:="naPrint" Karoo News[_2_] Excel Programming 1 January 30th 06 02:40 PM
Problem with "On error resume next" with "custom VLookup" Factivator Excel Programming 3 July 20th 04 04:42 PM


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