automatically run macro/module after import of .bas file

Posted on 2011-04-20
Last Modified: 2012-05-11
Hi all,

My code imports a module (.bas file) into an excel file (code is below) but I would like it to automatically run that same module after it is imported. I try to reference the macro name (TestMacro) in teh visual basic express 2010 project that i created but of course it can not refer to it. so is tehre a way to programmably run a macro/module liek this?

thanks in advance,

ExcelApp.ActiveWorkbook.VBProject.VBComponents.Import(directory2 & "\" & fileName2)

Open in new window

Question by:touyets17
    LVL 85

    Accepted Solution

    You can't run a module, only a routine, so you would basically use:

    ExcelApp.Run "'" & & "'!macro_name_here"

    Open in new window


    Author Closing Comment


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
    This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now