Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calling a macro with parameters

28 views
Skip to first unread message

Harold Combs

unread,
Jul 17, 2001, 6:01:04 PM7/17/01
to
First of all, you guys are a godsend!

Secondly, VB isn't as bad a language as I expected. . .


Ok, here goes:

I'm the guy trying to automatically generate HTML files out of
Project 2000. I recorded a macro in Project, and I've been trying to
alter it to do general translations based upon a standard template
here's my effort at the macro, which I put in my GLOBAL.MPT under
Module3:

Sub HMacro3(Infile as String, Outfile as String)
' Macro HMacro3
' Macro Recorded Tue 7/17/01 by Harold Combs.
FileOpen Name:=Infile, ReadOnly:=False, FormatID:="MSProject.MPP"
FileSaveAs Name:=Outfile,_
FormatID:="MSProject.HTML", _
map:="Default task information"
End Sub


Ok, so far so good...now, Here's my VB6 routine, or at least the
germane bits:

Private Sub Command1_Click()

' Declare object variables for Microsoft Excel,
' application workbook, and worksheet objects.
Dim projApp As MSProject.Application

Dim strInputFile, strTargetFile, strMacroName As String

strTargetFile = "C:\out.html"
strMacroName = "Module3!HMacro3"
strInputFile = "Z:\foo\bar.mpp"

Set projApp = New MSProject.Application
projApp.Visible = False

projApp.Run strMacroName, strInputFile, strTargetFile

projApp.Quit

' Release the object.
Set projApp = Nothing

End Sub


Ok, so here's the record of my travails: I've done a projApp.Macro()
call, and that works fine, but since I can't pass it any parameters
it's useless.

Initially, I did it all in VBA using FileOpen() and FileSaveAs(), but
I coudldn't get any HTML out of it (closest the function offers is
pjTXT, a text file).

projApp.Run() seemed like the perfect solution, but it just refuses to
do anything. . .

I've looked-up some examples on the MS support site, but they're all
in Excel( http://support.microsoft.com/directory/article.asp?ID=kb;en-us;Q153307
) is there something different about Project that precludes the Run
method from working as advertised?

Many thanks
HRC

Rick Williams

unread,
Jul 18, 2001, 12:00:01 PM7/18/01
to
I worked on this problem a couple of years ago, and never did really find a
solution. Any VBA routine with parameters would not be recognized by Project
as a macro. I resorted to another solution. I had my VB app write the
"parameters" to the Registry, and then my macro would read them from the
Registry when it started. This worked fine. You could write to a txt file,
if you preferred.
Regards,
Rick Williams

"Harold Combs" <hco...@hotmail.com> wrote in message
news:af14661d.01071...@posting.google.com...

Harold Combs

unread,
Jul 18, 2001, 1:53:52 PM7/18/01
to
Answering my own question...


Nevermind...I abandoned the Macro solution and went with pure VBA,
doing a FileOpen(), FileSaveAs() and FileClose(). Works like a charm
=-)

Now all I have to do is compile my function into a DLL, and call
it from a command-line C++ program. If anybody has any tips on this,
I'd appreciate it (I'm running VB5 SP5, and VC++ 6)

Harold

hco...@hotmail.com (Harold Combs) wrote in message news:<af14661d.01071...@posting.google.com>...

Venkata Krishna

unread,
Jul 28, 2001, 10:50:31 PM7/28/01
to
Harold
 
You can call a macro in a mpp project (not global.mpt) from VB6 by passing arguments .
You can call a macro in Gobal.mpt from a mpp project by passing arguments.
 
So you have 2 options
 
Option 1 : Move your macro to a mpp dummy project so that you can open it when needed and call from VB6
Option 2 : Keep your code in Global.mpt. Create a Dummy mpp project with a macro that calls the global.mpt macro. Keep the same arguments for macro in Dummy mpp project. Call this mpp project's macro from VB6 by passing arguments which in turn calls your main macro in global.mpt
 
Steps to implement option 2 (which automatically covers option 1) - a sample
 
Step 1: Put your macro in global.mpt's Module1, say as follows :
 
Public Sub MacroGlobal(s As String)
    MsgBox s
End Sub
 
Step 2: Create a dummy macro in a dummy project (say DummyProject.mpp) in ThisProject module  say as shown below (don't put it in a standard module). Set reference to ProjectGlobal entry in Tools|References. The macro should have same arguments as above and should in turn just call the above macro. Say the macro is as follows :
 
Sub MacroDummy(st As String)
    ProjectGlobal.MacroGlobal st
End Sub
 
Step 3: Create your VB6 project which can open the dummyproject.mpp and call it's MacroDummy
 
Dim prjApp As Object
Sub main()
    Set prjApp = CreateObject("MSProject.Application")
    prjApp.fileopen "d:\projectdocuments\dummyproject.mpp"
    prjApp.activeproject.MacroDummy "Hai"
End Sub
 
Regards
Venkata Krishna
 

 
 
 
 
0 new messages