code to see if dot-file contains code

L

Lina

Hi
I need to convert many .dot files to dotx or dotm. I would like to do
something like this
If mytemp has code then
save as dotm
else
save as dotx
End if
Can you do this with vba?
thanks
 
D

DaveLett

I think you're looking for something like the following:

If ActiveDocument.VBProject.VBComponents.Count > 1 Then
'''saveas dotm
Else
'''saveas dotx
End If

HTH,
Dave
 
M

macropod

Hi Dave,

Somewhat simpler:

Sub Demo()
With ActiveDocument
If .HasVBProject Then
'saveas dotm
Else
'saveas dotx
End If
End With
End Sub
 
L

Lina

Thank you, now I have a new problem, when I save the dot files as dotm or
dotx with vba the new files become corrupted and can not be opened

im using

mydoc.SaveAs FileName:=strFileName, _
FileFormat:=wdFormatTemplate

macropod said:
Hi Dave,

Somewhat simpler:

Sub Demo()
With ActiveDocument
If .HasVBProject Then
'saveas dotm
Else
'saveas dotx
End If
End With
End Sub


--
Cheers
macropod
[Microsoft MVP - Word]


DaveLett said:
I think you're looking for something like the following:

If ActiveDocument.VBProject.VBComponents.Count > 1 Then
'''saveas dotm
Else
'''saveas dotx
End If

HTH,
Dave
.
 
G

Graham Mayor

Save as (dotx)
FileFormat:=wdFormatXMLTemplate
or (dotm)
FileFormat:=wdFormatXMLTemplateMacroEnabled

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Lina said:
Thank you, now I have a new problem, when I save the dot files as dotm or
dotx with vba the new files become corrupted and can not be opened

im using

mydoc.SaveAs FileName:=strFileName, _
FileFormat:=wdFormatTemplate

macropod said:
Hi Dave,

Somewhat simpler:

Sub Demo()
With ActiveDocument
If .HasVBProject Then
'saveas dotm
Else
'saveas dotx
End If
End With
End Sub


--
Cheers
macropod
[Microsoft MVP - Word]


DaveLett said:
I think you're looking for something like the following:

If ActiveDocument.VBProject.VBComponents.Count > 1 Then
'''saveas dotm
Else
'''saveas dotx
End If

HTH,
Dave

:

Hi
I need to convert many .dot files to dotx or dotm. I would like to do
something like this
If mytemp has code then
save as dotm
else
save as dotx
End if
Can you do this with vba?
thanks
.
 
L

Lina

Thanks it works perfectly now!!!

Graham Mayor said:
Save as (dotx)
FileFormat:=wdFormatXMLTemplate
or (dotm)
FileFormat:=wdFormatXMLTemplateMacroEnabled

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Lina said:
Thank you, now I have a new problem, when I save the dot files as dotm or
dotx with vba the new files become corrupted and can not be opened

im using

mydoc.SaveAs FileName:=strFileName, _
FileFormat:=wdFormatTemplate

macropod said:
Hi Dave,

Somewhat simpler:

Sub Demo()
With ActiveDocument
If .HasVBProject Then
'saveas dotm
Else
'saveas dotx
End If
End With
End Sub


--
Cheers
macropod
[Microsoft MVP - Word]


I think you're looking for something like the following:

If ActiveDocument.VBProject.VBComponents.Count > 1 Then
'''saveas dotm
Else
'''saveas dotx
End If

HTH,
Dave

:

Hi
I need to convert many .dot files to dotx or dotm. I would like to do
something like this
If mytemp has code then
save as dotm
else
save as dotx
End if
Can you do this with vba?
thanks


.


.
 
G

Graham Mayor

You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Lina said:
Thanks it works perfectly now!!!

Graham Mayor said:
Save as (dotx)
FileFormat:=wdFormatXMLTemplate
or (dotm)
FileFormat:=wdFormatXMLTemplateMacroEnabled

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Lina said:
Thank you, now I have a new problem, when I save the dot files as dotm
or
dotx with vba the new files become corrupted and can not be opened

im using

mydoc.SaveAs FileName:=strFileName, _
FileFormat:=wdFormatTemplate

:

Hi Dave,

Somewhat simpler:

Sub Demo()
With ActiveDocument
If .HasVBProject Then
'saveas dotm
Else
'saveas dotx
End If
End With
End Sub


--
Cheers
macropod
[Microsoft MVP - Word]


I think you're looking for something like the following:

If ActiveDocument.VBProject.VBComponents.Count > 1 Then
'''saveas dotm
Else
'''saveas dotx
End If

HTH,
Dave

:

Hi
I need to convert many .dot files to dotx or dotm. I would like to
do
something like this
If mytemp has code then
save as dotm
else
save as dotx
End if
Can you do this with vba?
thanks


.


.
 

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