Copy form from Project to Project

R

rongchaua

Is there a way to copy the source code (Form,Modul) from a project to another
project with VBA?
All supports will be appreciated. Thanx.
Tri Nguyen.
 
R

rongchaua

I have found a solution. I export the Componente(Form,Modul) manually to a
directory and then use the Import function of vbcomponente to import these to
another project.
Other solutions will be appreciated. Thanx.
Tri Nguyen.
 
J

Jan De Messemaeker

Hi,

You can copy the whole module or the form through OrganizerMoveItem.
HTH
 
R

rongchaua

Hi Jan,
thanx for your answer. But when I use command OrganizerMoveItem as below

OrganizerMoveItem type:=pjForms,filename:= source.mpp, tofilename:=dest.mpp,
name:= "frmTest"

I receive an error 1101 "File source.mpp could be not found". But I can
really open this source.mpp with command FileOpen source.mpp.
Can you help me with it?
Thanx.
Tri.
 
R

rongchaua

Thanx Jan, Thanx Rod
i can solve this problem. The source.mpp must be opened.
Thanx for your supports.
Tri.
 
R

rongchaua

Hi all,
i could already move the forms,modules,views,tables,filters,.... In my
"source.mpp" at the event Project_Open i have such a source code

Private Sub Project_Open(ByVal pj As Project)
AdjustToUseTool
End Sub

My question is: How can I move this source code to "dest.mpp" programmtically?
All helps will be appreciated.
Thanx.
Tri.
 
J

Jan De Messemaeker

Haha!
I would dearly like to know
I gave up using Project_Open because of this and use a sub Auto_Open in a
"normal" module which has the sameeffect but can be copied.
Hope someone knows better..
 
R

rongchaua

Hi Jan,
thanx you for your answer. I have another idea. I delete all old source code
and then replace with new source code. Can you tell me more about your way? I
don't know how i should do with your solution :

+++++
strComponent = "ThisProject"
strProcedure = "Project_Open"
strNewText = "Private Sub Project_Open(ByVal pj As Project)" +
vbCrLf + _
"AdjustToUseTool" + vbCrLf + _
"End Sub"
For i = 1 To Application.Projects.Count
Set tmpProject = Application.Projects(i)
If tmpProject.Name = "MasterDatei.mpp" Then
ElseIf tmpProject.Name = "Vorlage.mpp" Then
Else
With tmpProject.VBProject
Set objVbCodeModule =
..VBComponents(strComponent).CodeModule
If Not objVbCodeModule Is Nothing Then
With objVbCodeModule
lStartLine = .ProcStartLine(strProcedure,
vbext_pk_Proc)
lLineCounter = .ProcCountLines(strProcedure,
vbext_pk_Proc)
.DeleteLines lStartLine, lLineCounter
.AddFromString strNewText

End With
End If
End With
End If
Next i
+++++

All comments will be appreciated.
rca.
 
R

rongchaua

Hi all,
there is also another problem. When I use this command

OrganizerMoveItem Type:=pjFields, FileName:="source.mpp",
tofilename:="dest.mpp", Name:="Text20"

i have received an error. Error 1101 "Illegal value of argument". I really
don't know how i can fix this error.
Any idea?
Thanx for all supports.
rca.
 
J

Jan De Messemaeker

Hi Rongchua,

What I found is that in the module I wrote for this a couple of years ago,
for any sort of reason I copy all the customized fields (leaving out the
name argument) Maybe it didn't work with the name?
HTH
 

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

Top