+ Reply to Thread
Results 1 to 7 of 7

Can I write code that can get VBE settings?

  1. #1
    Forum Contributor
    Join Date
    05-27-2014
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    2007 & 2010
    Posts
    273

    Can I write code that can get VBE settings?

    I'm trying to write an add-in that will copy code from an Excel VBProject to Word so I can "Pretty Print" it. Can I query some of the VBE settings? I'll probably need to query more settings but specifically right now I want to query what colours are currently set for the code's keywords, identifiers and comments.
    Please click *Add Reputation if I've helped

  2. #2
    Forum Contributor
    Join Date
    05-27-2014
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    2007 & 2010
    Posts
    273

    Re: Can I write code that can get VBE settings?

    I haven't found anything on either ExcelForum or Google that tells me I can do this. I'm hoping a bump to the top of the forum will mean someone will see this that didn't before and can help me out with it??

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Can I write code that can get VBE settings?

    Why do you need to know the VBE settings?

    Couldn't you use some standard formatting so you end up with standard, pretty output?
    If posting code please use code tags, see here.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Can I write code that can get VBE settings?

    Quote Originally Posted by kadeo View Post
    I'm trying to write an add-in that will copy code from an Excel VBProject to Word so I can "Pretty Print" it. Can I query some of the VBE settings?
    While it's possible to access the VBE, t you'd need to give trusted access to the VBA project model; something that is not recommended unless there's no other way of achieving the same outcome. Do note that, when you export VBA code to Word, all the character formatting you see in the VBE is lost; only indents are retained. Consequently, you'll have a lot of work ahead of you if you want to generate anything with formatting like you see in the VBE. Even if you could access Keyword colours etc., none of those attributes is carried over and you'd have to recreate them from scratch.
    Last edited by macropod; 11-30-2015 at 11:02 PM.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Can I write code that can get VBE settings?

    This will get the code from an Excel module, open Word, create a new document and put that code into the new document.
    Word should not be open when you run this.

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Can I write code that can get VBE settings?

    Quote Originally Posted by mikerickson View Post
    This will get the code from an Excel module, open Word, create a new document and put that code into the new document.
    Word should not be open when you run this.
    Only if you have a code module named 'Module1' and only for that code module. If there's no 'Module1' (e.g. because all the code is in the 'ThisWorkbook' module, a sheet module or a userform), all you'll get is an error message.

    It shouldn't matter whether Word is open, but what does matter is:
    • you also need to give trusted access to the VBA project model or the code won't work;
    • your code doesn't save the document; and
    • your code leaves an orphaned Word session containing the unsaved document running in the background.

  7. #7
    Forum Contributor
    Join Date
    05-27-2014
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    2007 & 2010
    Posts
    273

    Re: Can I write code that can get VBE settings?

    Thanks for the responses guys. I've been offline for a couple of weeks and only seeing these now.

    As it happens, I'm good as far as exporting the actual code to Word is concerned. And while I know I have a lot of work ahead in terms of formatting the output, I'm prepared for it. Also, I know the objective will require access to the VBA project model and I'll make this clear to anyone who runs the resulting add-in.

    The only solutions to what I'm doing that I can find online at the moment involve installing some other program to do the work but a lot of companies restrict employees from installing programs. A VBA add-in is a niche I hope to fill.

    Back to my OP though...
    Quote Originally Posted by Norie View Post
    Why do you need to know the VBE settings?

    Couldn't you use some standard formatting so you end up with standard, pretty output?
    Thanks, norie I could do that, in fact that is one of the options the add-in provides. But in the interests of giving options to the user, one I was hoping to add is to allow the user to just use the colours they have already set up in the VBE without having to reselect them all in my add-in and for that I need to query the existing settings. I'd also need to do this for the font they use, the point size and so on.

    I will at some point need to start a thread about identifying a list of all the keywords or reserved words used in VBA but I will save that for a separate thread. I'm kind of getting the impression that there is no direct way to do what I need here. But, like I said, there are third party programs that can do it. What about using some kind of API to query the contents of a window like I need to do if I want my code to enter the password to open a locked VBA project for instance. Could that be a way to get what I need?

+ 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] Code Problem: How to Write this into a VBA code
    By rlkerr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2013, 02:46 AM
  2. [SOLVED] IF Exists or on Error Then - Skip Code- How to write code?
    By Jack7774 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2013, 06:45 PM
  3. VBA Code to modify printer duplex settings for one Sheet of a workbook
    By ben.collins in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-04-2012, 08:45 AM
  4. VBA Code to setup print settings for all worksheets within a work book.
    By anfdrew in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-23-2012, 09:58 PM
  5. [SOLVED] One of the Settings in Options Trust Center Settings is Grayed out
    By zit1343 in forum Excel General
    Replies: 2
    Last Post: 06-28-2012, 09:18 AM
  6. Writing code to modify the settings ?
    By aca in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-26-2009, 02:04 PM
  7. Code to write out all lines of code
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-04-2005, 11:26 PM
  8. VB code changed Excel settings for all worksheets
    By JenniferMc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-15-2005, 04: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