473,383 Members | 1,953 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,383 software developers and data experts.

How to fix error when executing macro: "Compile Error Variable not defined"?

Below is my code. The error is "Compile Error Variable not defined". wdOrientLandscape is highlighted. Again this the portion of the code from a VB module created in Excel. The previous lines of code are passing cell contents from a worksheet and then into the variable that are shown in the respective lines for each occurance of .TypeText:=
By the way the next i is a counter to ensure all the rows in the active worksheet are passed to to the variables and thereby printed.

Expand|Select|Wrap|Line Numbers
  1. ' Send commands to Word
  2.      With WordApp
  3.       .Documents.Add
  4.       .PageSetup.Orientation = wdOrientLandscape
  5.          With .Selection
  6.           .Font.Size = 14
  7.           .Font.Bold = True
  8.           .ParagraphFormat.Alignment = 1
  9.           .TypeText Text:="E C R"
  10.           .TypeParagraph
  11.           .TypeParagraph
  12.           .Font.Size = 12
  13.           .ParagraphFormat.Alignment = 0
  14.           .Font.Bold = False
  15.           .TypeText Text:="Date Created:" & vbTab & DateCreated & vbTab
  16.           .TypeText Text:="Initiated By:" & vbTab & _
  17.                    Application.UserName
  18.           .TypeParagraph
  19.           .TypeText Text:="Serial Number:" & vbTab & SerialNumber
  20. '               .TypeText message
  21.           .TypeText Text:="Tool Name:" & vbTab & ToolName
  22.           .TypeText Text:="Drawing Number:" & vbTab & DrawingNumber
  23.           .TypeText Text:="Drawing Title:" & vbTab & DrawingTitle
  24.           .TypeText Text:="Revision:" & vbTab & Rev
  25.           .TypeText Text:="Change Request:" & vbTab & ChangeRequest
  26.           .TypeText Text:="Change Reason:" & vbTab & ChangeReason
  27.           .TypeText Text:="Additional Information:" & vbTab & AddlInfo
  28.          End With
  29.             .ActiveDocument.SaveAs Filename:=SaveAsName
  30.      End With
  31.  
  32.     Next i
  33.  
  34. '   Kill the object
  35.     WordApp.Quit
  36.     Set WordApp = Nothing
  37.  
Nov 19 '10 #1
4 5421
Guido Geurs
767 Expert 512MB
For word 2003 it's:
Expand|Select|Wrap|Line Numbers
  1. With Word
  2. .WdOrientation = wdOrientLandscape
Nov 19 '10 #2
Thank you VERY much for response, however I failed to specify that I am working with Excel 2007 and Word 2007. I mention this because I actually already tried the fix you had suggested.
Nov 19 '10 #3
Stewart Ross
2,545 Expert Mod 2GB
The constant wdOrientLandscape remains the same in the Office 2007 version. It has the value 1 (the corresponding portrait version, wdOrientPortrait, has the value 0).

Constants like wdOrientLandscape will only be available to the compiler if you have explicitly declared a reference to the Word object library (using Tools, References from the VB editor). If you are using late binding where you don't need to reference the object library the constants will not be available.

The equivalent statement without use of the symbolic constant is

Expand|Select|Wrap|Line Numbers
  1. .pagesetup.orientation = 1
As an aside, I note that you have a With .Selection in your code. I am assuming that you actually have a Select statement somewhere before the segment you show, as otherwise the With .Selection is not going to work.

-Stewart
Dec 2 '10 #4
Stewart,

Thank you very much! Your code worked like a charm! I'm not too sure why the With .Selection is working because I do not have a Select statement anywhere in my code.
P.S. I am using late binding. I am going to have study the late binding concept because I am not familiar with it. I borrowed the code from an example that a friend had and modified it considerably.

Thanks a Million!
Dec 2 '10 #5

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

Similar topics

4
by: Dmitry | last post by:
Hello, Sometimes on js code execution Mozilla 1.5 prints in JS concole the following error: "Error: fn is not defined" where "fn" is the function name surely defined _before_ the line that...
1
by: Steve | last post by:
I get this message when I tried to make a .MDE of my database. "Compile error in hidden module: Form_frmPurchaseReq" I have been using this database for several months and just thought I would...
10
by: Chris LaJoie | last post by:
Our company has been developing a program in C# for some time now, and we haven't had any problems with it, but just last night something cropped up that has me, and everyone else, stumped. I...
2
by: yinglcs | last post by:
I have the following code, which use template as the parent class of my other class. But I have "instantiated from here" compile error at this line: class C: public B2<A>. Can some one...
3
by: wwwursa | last post by:
I am trying to use the Right function in a VB6 program. I have used it used many times before in other programs. When I press the enter key after entering the code line, the word "Right" turns...
6
by: JHNielson | last post by:
This is a very simple question.... I have a form that looks up Records for an unbound drop-down list. It has worked just fine up until last night. Now the button on the form to delete a record...
6
by: newholborn | last post by:
Hi everyone. I have some questions, which should be rather easy to reply, but as I am working on PHP, JavaScript, XML, CSS, Photoshop and other stuff at the same time, my head, which is about to...
0
benchpolo
by: benchpolo | last post by:
I am currently modifying an existing DTS process by adding a new field in the Transformation task. This process queries data from SQL tables and import it to MSExcel. Steps 1. Drop the table...
1
by: Dorota Prywata | last post by:
Hi, I need help with VBA Macro for Auto-filter to high lite a header plp advice as per below course a I got Compile error: Expected End Sub ? Sub Macro1() Function FilterOn(myCell As Range)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.