Consulting

Results 1 to 2 of 2

Thread: Passing Excel macro variable to access macro

  1. #1
    VBAX Newbie
    Joined
    Mar 2016
    Posts
    3
    Location

    Passing Excel macro variable to access macro

    Hello,
    I have some information in Excel that I want to pass to Access macro, I found some examples on the internet, but could not get any of them to work.

    Here is the Excel code:

    Sub DB_macro()
    
    
    Dim A As Object
    Dim xlVar As String
    Dim myRng As Range, myC As Range
    
    
    Set myRng = ThisWorkbook.Worksheets("List").Range("List[DB]")
    
    
    For Each myC In myRng
    
    
    xlVar = myC.Value2
    Set A = CreateObject("Access.Application")
    A.Visible = True
    A.OpenCurrentDatabase "C:\DB.accdb"
    A.DoCmd.RunMacro "Access_macro", xlVar
    DoEvents
    A.CloseCurrentDatabase
    A.Quit
    Set A = Nothing
    
    
    Next myC
    
    
    End Sub
    Access function:
    Function ChangeA(xlVar As String)
    
    
    DBA = "DB_" & xlVar
    Call ChangeB
    DoEvents
    
    
    End Function
    Macro Access_macro I am calling has just this: ChangeA(xlVar)

    But it does not work, I get error saying that data type is wrong for one of the arguments.

  2. #2
    VBAX Newbie
    Joined
    Mar 2016
    Posts
    3
    Location
    Nevermind, I change A.DoCmd.RunMacro to A.Run to run function itself and it worked fine.

Posting Permissions

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