Re: Pass variable to Excel Macro from Access

Re: Pass variable to Excel Macro from Access

am 30.03.2008 14:51:07 von Kc-Mass

This is untested air code but very close. Pass this a string with the full
path and name of the Workbook.

Sub FillCell(FileToWriteIn)
Dim strWrkBkName As String
Dim xlApp As Object
Dim wbExcel As Object
strWrkBkName = FileToWriteIn
Set xlApp = CreateObject("Excel.Application")
Set wbExcel = xlApp.Workbooks.Open(strWrkBkName)
wbExcel.Sheets(1).Range("A1") = "The String For the Macro"
xlApp.Quit
Set xlApp = Nothing
Set wbExcel = Nothing
End Sub


Kevin

"Niranjan" wrote in message
news:4dc64b22-3094-4629-9c1c-c2e516f6ba2e@i29g2000prf.google groups.com...
On Mar 28, 3:37 am, "KC-Mass" wrote:
> Couln't you just store the value in a cell of the worksheet and have the
> Macro reference the cell?
>
> Kevin
>
> "Niranjan" wrote in message
>
> news:f4e83832-7e50-4c1d-881f-41b6c5714e40@p25g2000hsf.google groups.com...
>
>
>
> >I have an Excel macro that I execute from Access. I want to change it
> > so that I can pass a variable (filename) from Access to the Excel
> > Macro. This will allow me to import a different file everytime I
> > execute the macro.
>
> > Does anyone know how to do this?- Hide quoted text -
>
> - Show quoted text -

Kevin:
Thanks for the response. I think that will work.
However I am not sure how to write a string from Access into a Excel -
Sheet1 - Cell A1.
If anyone knows. please let me know. Thanks.