473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to fix Compile Error: With object must be User-Defined Type, Object or Variant

Hi, this is my first post so hoping I do this right. I am trying to run a SUB in Microsoft Visual Basic for Applications, but I keep getting the following error: "Compile Error: With object must be User-Defined Type, Object or Variant." The SUB is attempting to freeze panes in many worksheets within an Excel workbook (Excel 2010). This is the remedy posted by Microsoft, but I am not sure what this means or what I need to do: "The With...End With block can't be used with all variable types. This error has the following cause and solution: You tried to use a variable that was not of Object type, user-defined type, or Variant type containing an object within a With block. Check to see if you misspelled the name of the object, user-defined type, or Variant variable." I am new to VB so I don't know what this means. I just know this worked last year and now it doesn't. Is there possibly a setting that needs to be checked in VB? I found one solution for another user was to "check" something that was unchecked in Tools>References, but I am not sure what needs to be checked that isn't already. Thanks, my SUB is below:

[Sub FPR_15_freeze_panes()

Dim ws As Worksheet
For Each ws In Worksheets
Range("G2").Select
With ActiveWindow.FreezePanes = True

End With

Next ws

MsgBox ("Done!")]
Jan 10 '17 #1
2 4287
Luk3r
300 256MB
Did you recently upgrade your version of Microsoft Office? You may need to add the newer reference to the project.
Jan 10 '17 #2
No, I don't think we have for a few years. I did recently install a MS Add-in to Excel that uses a VB program, I thought that might be suspect. But I have an update on this. By modifying some of the code someone got it to work! Here is the new code:
Sub FPR_15_freeze_panes()

[Dim Ws As Worksheet
Application.ScreenUpdating = False
For Each Ws In Application.ActiveWorkbook.Worksheets
Ws.Activate
Range("G2").Select
With Application.ActiveWindow
.FreezePanes = True
End With
Next
Application.ScreenUpdating = True
MsgBox ("Done!")

End Sub]
Jan 10 '17 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Richard Hollenbeck | last post by:
I have two functions (one using the other) where I want to pass into it the character A, B, C, D, or F and have it return a Double indicating the minimum score it takes to get that grade. For...
2
by: dpm | last post by:
I'm trying to create a simple X Windows/openGL executable on an SCO Unix machine and get the following error when running make: /u//lib/libGL.a (g_render.o): fatal error: /u//lib/libGL.a...
1
by: MLH | last post by:
After following the instructions at http://support.microsoft.com/?id=258049 I get an error at compile time complaining about c As CloseCommand Function InitApplication()...
2
by: Faheem Mitha | last post by:
Hi, The following bit of code compiles fine with gcc 3.3 or later, but has problems with the Intel C++ compiler version 9.1, which produces the following error message. Is this a compiler...
13
by: forrestgump | last post by:
I am currently trying to use the below VBA to import information into excel from access. This VBA is in the excle sheet:- Public Sub getrs() Dim adoconn As ADODB.Connection Dim adors As...
1
by: coolminded | last post by:
hello all, i'm using vb6 and sql. whenever i compile my project it shows the message "User-defined not defined". i have kept all the references associated with my project. even though, it shows...
6
by: travjbad1 | last post by:
I am new to the forum and new to Access, so please be simple and descriptive if possible. I am having a problem with a button on a form that saves, opens a report in pdf, and emails the report to the...
1
by: WECcoder | last post by:
This code used to work prior to our group IT update to Word I thought Word.Application was a generic type defined to Access? Private Sub cmdDatasheetsDigital_Click() Set db = CurrentDb Dim Wrd...
0
by: usharani K | last post by:
Urgent Help !!!!!!!!!!!while compiling the code I am getting the compile error: Compile error: User-defined type not defined in form_load. ---------------------------- Private Sub Form_Load() ...
5
by: suneelkp | last post by:
Hi everyone, I am trying to use the code from internet to create and populate a tree view control. But in the first line itselef I am getting error in " Dim node As node". Compile error:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.