Unable to Compile a Macro

B

Bobby

Hi ,
I am trying to compile the following code.But iam getting the following error:
Error
*****
User Defined Type not define :
Public fso As New Scripting.FileSystemObject
*****
Code
*****
Option Explicit

Public fso As New Scripting.FileSystemObject

Public vertView As Boolean


Public Sub Auto_Open()
On Error GoTo ErrorHandler

Dim newMenu As Menu, menuName As String


menuName = Application.MenuBars(xlWorksheet).Menus("MainMenu").Caption

Exit Sub
ErrorHandler:
If Err.Number = 1004 Then
Set newMenu =
Application.MenuBars(xlWorksheet).Menus.Add("&MainMenu", _
Application.MenuBars(xlWorksheet).Menus.Count)

newMenu.MenuItems.Add "E&xport Data File ...", "ExportToFile"
End If
End Sub
 
D

Dave Peterson

First, make sure you set a reference to "Microsoft Scripting Runtime"
(Under Tools|References)

But there's nothing in your posted code that uses FSO.

Second, Chip Pearson explains why it's not good to use:

Dim Something As New SomeObject
here:
http://www.cpearson.com/excel/DeclaringVariables.aspx
look for
Don't Use Auto-Instancing Object Variables
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top