launching excel, opening a file, and running a macro automatically

  • Thread starter Thread starter Bernie Yaeger
  • Start date Start date
B

Bernie Yaeger

I call excel from a vb .net app with
launchstring = "c:\program files\microsoft office\office10\excel.exe
f:\imcapps\dbffiles\revacrz.dbf

Shell(launchstring, AppWinStyle.NormalFocus)

Now I want also to launch a macro at the end of revacrz.dbf - any way to do
this?

Thanks for any help.

Bernie Yaeger
 
I don't know anything about VB.Net.

But maybe you could create a script (like .VBS).

I could control excel from MSWord with something like:

Option Explicit
Sub testme01()

Dim objExcel As Object
Dim objWkbk As Object
Dim objDBF As Object

Set objExcel = CreateObject("excel.application")
objExcel.Visible = True

Set objDBF = objExcel.workbooks.Open("C:\my documents\excel\book1.dbf")
Set objWkbk = objExcel.workbooks.Open("C:\my documents\excel\macros.xls")
objExcel.Run objWkbk.Name & "!testme"

objWkbk.Close False
objExcel.Quit

Set objDBF = Nothing
Set objWkbk = Nothing
Set objExcel = Nothing

End Sub

And my Testme macro in macros.xls looked like this:

Option Explicit
Sub testme()

With Workbooks("book1.dbf").Worksheets(1)
.Columns(1).ColumnWidth = 5
.Parent.Save
.Parent.Close savechanges:=False
End With

End Sub

Notice that I closed the macro workbook in the calling macro, but closed the DBF
file in the called macro. But you could do it whereever you wanted.
 
Hi Dave,

Tx for the response.

I don't open Excel as you are doing, but it's an interesting idea, and, yes,
I could do basically the same inside vb .net using the excel ojb model.

I'll play around with it and give it a try - thanks again for the idea.

Bernie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top