+ Reply to Thread
Results 1 to 5 of 5

Printing out the VBA code to a file or printer

  1. #1
    Registered User
    Join Date
    04-14-2021
    Location
    Camas, WA
    MS-Off Ver
    Office 365
    Posts
    2

    Printing out the VBA code to a file or printer

    OK. I am new here. I have been using Excel for years and am designing an Estimating workbook for the printer that I work for (I am a printer also).

    Two things have me stumped . . .

    1) How to declare a variable (filename specifically) for global use throughout the workbook.
    2) How to print out the VBA code to a file or a printer.

    Both seem obviously easy but I am totally baffled.

    I used to program computers for a living (FORTRAN, BASIC, Pascal) but this Excel VBA stuff has me scratching my head and I don't want to go bald.

    Thanks for any help or directions that I can be pointed.

    Gary

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Printing out the VBA code to a file or printer

    You can declare a global variable at the top of a module with the format

    Please Login or Register  to view this content.
    A variable declared at the top of a module is global to that module, and if Public is used it is global everywhere.

    You can print your code by right-clicking on the project name (i.e., file name) in the VBA development environment and selecting Print. You can print to paper, or print to a PDF if you have a PDF print driver installed (I think Windows comes with one). I do not know of a way to dump all the code to a single plain text file, but maybe there is a way. You can also export individual modules, which are .bas files but these are plain text files with a one-line header.

    P.S. My first job was FORTRAN programming in 1979
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    04-14-2021
    Location
    Camas, WA
    MS-Off Ver
    Office 365
    Posts
    2

    Re: Printing out the VBA code to a file or printer

    OK. I tried using the "Public VariableName As DataType" but I keep getting Compiler Error: Invalid Attribute or Sub Function.

    I was getting that same error when I first tried using "Public". What am I doing wrong because the computer is never wrong?

    I was able to print the VBA code so at least that worked.

  4. #4
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,411

    Re: Printing out the VBA code to a file or printer

    You could use a commercially available piece of software.
    The one I use does all the indentation and loop traces - very handy for that elusive error - eliminates many a frustration.
    I have no financial interest in any apps - just merely pointing out that they are available and very useful at modest cost.
    torachan.
    Attached Files Attached Files

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Printing out the VBA code to a file or printer

    Quote Originally Posted by Garish View Post
    OK. I tried using the "Public VariableName As DataType" but I keep getting Compiler Error: Invalid Attribute or Sub Function.
    Hopefully you did not type that in just like that. It is just a model to show the syntax. The Public keyword was the important part. An actual declaration would look like

    Please Login or Register  to view this content.
    It must appear before the first Sub or Function. If you use Option Explicit it must occur after that.

    Now the variable FileName can be referenced anywhere in the project.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] network printer code help for not printing when action cancelled
    By lilsnoop in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2021, 11:47 AM
  2. Replies: 1
    Last Post: 06-30-2017, 10:29 AM
  3. [SOLVED] Solution to changing Default printer code when printer changes
    By Sintek in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 10-28-2016, 03:12 PM
  4. VBA code to use default printer on local pc for printing
    By DanishDudeAU in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-13-2013, 02:40 AM
  5. Printing labels on a dot matrix printer - what does this code do
    By Laurence Lombard in forum Excel General
    Replies: 2
    Last Post: 06-19-2006, 08:25 AM
  6. [SOLVED] Printing labels on a dot matrix printer - what does this code do
    By Laurence Lombard in forum Excel General
    Replies: 0
    Last Post: 06-18-2006, 02:25 AM
  7. [SOLVED] Code not printing to color printer
    By Brad in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-04-2005, 07:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1