Results 1 to 4 of 4
  1. #1
    bcn1988 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2012
    Posts
    7

    Import .BAS file into Excel VBE window from Access VBE

    Hello,

    I have an excel file that has been exported from Access. Since this is a brand new file, there are no modules saved to this excel spreadsheet. I have been attempting to import a saved .BAS file to EXCEL VBE with VBA code from Access VBE. I am able to import the .BAS file, however the module is being imported into Access VBE when I need it to upload into Excel VBE. Please see the code below that I have in Access VBE.


    Sub TestImportBAS()

    Dim TheDate As String
    Dim TheDate1 As String
    Dim FileDirectory As String
    TheDate = Format(Date, "MM-DD-YYYY")
    TheDate1 = Format(Date, "MMDDYYYY")



    FileDirectory = "C:\Documents and Settings\htq972\Desktop\Work Files\VBA Modules\POR & PMOR VBA\Excel Modules\2nd Module\Rename_Export_Tabs.bas"

    Application.VBE.ActiveVBProject.VBComponents.Impor t (FileDirectory)
    End Sub



    Please help! I need to roll this out ASAP! Thanks

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I would start by opening Excel and recording a macro. Record the steps you would do to insert a new module and import the .BAS file.
    That will show you the VBA required to create the module and import the bas file.

    In Access, the Access VBA code would need to create an instance of (open) Excel. You would use the reference to Excel (instead of Application) to execute the Excel VBA that would create the module and import the BAS file.

  3. #3
    bcn1988 is offline Novice
    Windows XP Access 2007
    Join Date
    Dec 2012
    Posts
    7
    Hey steve,

    I tried what you said, however there was no code that was recorded when I tried importing .BAS file into VBE. Regardless, this isn't the problem. I need the code for access VBA to open the VBE for Excel and import the .BAS into Excel VBE. Somewhere in my one line code (see below) is this issue:

    Application.VBE.ActiveVBProject.VBComponents.Impor t (FileDirectory)

    What is wrong with this coding and why is the module being imported into Access VBE?

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Is there really a space in ".Impor t"

    As far as I can tell, "Application" is referring to Access. That is why I suggested creating an Excel object (in Access VBA code). Something like this.. I cut this example code From Ken Snell's site:

    Code:
    Dim blnHasFieldNames As Boolean, blnEXCEL As Boolean, blnReadOnly As Boolean
    Dim lngCount As Long
    Dim objExcel As Object, objWorkbook As Object
    Dim colWorksheets As Collection
    Dim strPathFile as String, strTable as String
    Dim strPassword As String
    
    ' Establish an EXCEL application object
    On Error Resume Next
    Set objExcel = GetObject(, "Excel.Application")
    If Err.Number <> 0 Then
          Set objExcel = CreateObject("Excel.Application")
          blnEXCEL = True
    Err.Clear
    On Error GoTo 
    End If
    .
    .
    .
    
    objExcel.VBE.ActiveVBProject.VBComponents.Import (FileDirectory)
    To control Excel through automation, you have to reference Excel.

    I know this won't work, but you see where I am headed???

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Import to Access from Excel File created by ASP Page
    By tssrshot in forum Import/Export Data
    Replies: 3
    Last Post: 11-29-2012, 03:52 PM
  2. Replies: 1
    Last Post: 04-20-2012, 07:20 AM
  3. Import Excel file to Access
    By emmett in forum Import/Export Data
    Replies: 3
    Last Post: 04-06-2012, 05:27 AM
  4. Splitting an Excel File into Multiple Access Tables on Import
    By TheWolfster in forum Import/Export Data
    Replies: 4
    Last Post: 04-29-2010, 04:52 AM
  5. Replies: 0
    Last Post: 04-29-2009, 04:27 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums