+ Reply to Thread
Results 1 to 4 of 4

Problem with declarations it seems

  1. #1
    Registered User
    Join Date
    04-03-2012
    Location
    Stockholm
    MS-Off Ver
    Excel 2003
    Posts
    33

    Problem with declarations it seems

    Hello,

    I am trying to insert a macro in another workbook with vba. I found a a very good example for this and copied it. When I run code below I get an error message on first declaration "Dim VBProj as VBIDE.VBProject". It says "User defined type not defined".

    Any ideas?

    ---------------------------------------------------------------------------
    Sub CreateGraphMacro()
    Dim VBProj As VBIDE.VBProject
    Dim VBComp As VBIDE.VBComponent
    Dim CodeMod As CodeModule
    Dim LineNum As Long
    Const DQUOTE = """" ' one " character

    Set VBProj = ActiveWorkbook.VBProject
    Set VBComp = VBProj.VBComponents("Module1")
    Set CodeMod = VBComp.CodeModule

    ActiveSheet.Buttons.Add(5, 5, 50, 15).Select
    Selection.OnAction = Test
    Selection.Characters.text = "Button"

    With CodeMod
    LineNum = .CountOfLines + 1
    .InsertLines LineNum, "Public Sub Test()"
    LineNum = LineNum + 1
    .InsertLines LineNum, ".........."
    LineNum = LineNum + 1
    .InsertLines LineNum, "End Sub"
    End With

    End Sub

    ------------------------------------------------------------------------------

    Thanks,
    Stefan

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Problem with declarations it seems

    Hi,

    In the VBE go to the Tools menu, Select References and scroll down the list looking for 'Microsoft Visual Basic For Applications Extensibility n.n' where n.n will be some version number (mine is 5.3 for instance).
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Problem with declarations it seems

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Problem with declarations it seems

    ...just for the record I answered this post directly from the pop up description that appears when you hover over a header.

+ 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. problem with syntax on simple Class declarations and Sub declarations
    By ocean_engineer in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-28-2011, 03:59 AM
  2. declarations
    By jimbo_jones in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-23-2005, 01:50 PM
  3. Declarations variables, Dim, some guidance please
    By Neal Zimm in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 08-17-2005, 04:05 PM
  4. Declarations Procedure and Duplicate Declarations
    By Neal Zimm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-30-2005, 08:05 PM
  5. Understanding declarations
    By Greg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-26-2005, 06:06 PM

Tags for this Thread

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