Simple macro used to work...?

K

Kenneth

Howdy,

I have a very simple macro that was used to open the save
dialog to a particular folder. It would not assign a file
name. I would then type in the filename, and save.

It worked fine for many months.

Now, I get an error telling me that "This is not a valid
filename."

Here's the code:



Sub CorresSave()
'
' CorresSave Macro
'
ChangeFileOpenDirectory "F:\Corres06\"
ActiveDocument.SaveAs FileName:="", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False,
SaveFormsData:=False, _
SaveAsAOCELetter:=False
End Sub



Thanks for any help on this,
 
G

Graham Mayor

I can't see why it ecer worked with a filename seat as ""

Try

Sub CorresSave()
ChangeFileOpenDirectory "F:\Corres06\"
FileSaveAs
End Sub

Instead


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Kenneth

I can't see why it ecer worked with a filename seat as ""

Try

Sub CorresSave()
ChangeFileOpenDirectory "F:\Corres06\"
FileSaveAs
End Sub

Instead


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

My web site www.gmayor.com

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


Hi Graham,

I very much appreciate your speedy response, but it has a
problem that you may be able to resolve.

When I run this:


Sub CorresSave2()
'
' Macro1 Macro
' Macro recorded 9/25/2006 by
'
ChangeFileOpenDirectory "F:\Corres06\"
FileSaveAs
End Sub


I get the error "Sub or function not defined" with the
yellow on FileSaveAs.

Can you assist further?

Sincere thanks,
 
G

Graham Mayor

Oops - my fault. I called a simple routine from the macro which I didn't add
:(
Add the following :

Sub FileSaveAs()
Dialogs(wdDialogFileSaveAs).Show
ActiveWindow.Caption = ActiveDocument.FullName
End Sub
Sub CorresSave()
ChangeFileOpenDirectory "F:\Corres06\"
FileSaveAs
End Sub


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Kenneth

Oops - my fault. I called a simple routine from the macro which I didn't add
:(
Add the following :

Sub FileSaveAs()
Dialogs(wdDialogFileSaveAs).Show
ActiveWindow.Caption = ActiveDocument.FullName
End Sub
Sub CorresSave()
ChangeFileOpenDirectory "F:\Corres06\"
FileSaveAs
End Sub

Hi Graham,

Please accept my thanks,
 
K

Kenneth

On Tue, 26 Sep 2006 08:27:07 +0300, "Graham Mayor"


Hi again Graham,

Perhaps you can help me with another one.

It is a similar story:

The macro used to work properly under Win 2000 Pro. Now, I
have it on an XP box, and it has a (small) problem.

Below is code that is to print nametags. It used to work
with no intervention, but now, it works properly until
displaying the Print Dialog. The dialog shows the correct
printer (OKI) but just sits there until I manually click
"OK" to actually launch the printing.

I have experimented quite a bit with SendKeys "~" to try to
get past the dialog, but have had no luck.






Sub Nametags()
'
' Nametags Macro
' Macro recorded 7/18/2000 by Kenneth Sole
'
Documents.Add Template:= _
"F:\Templates\Label 4x2.dot" _
, NewTemplate:=False, DocumentType:=0
Documents.Open FileName:="Z:\Data\let.txt",
ConfirmConversions:=False, ReadOnly:= _
False, AddToRecentFiles:=False,
PasswordDocument:="", PasswordTemplate:= _
"", Revert:=False, WritePasswordDocument:="",
WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto
Selection.TypeText Text:="Last" & vbTab & "First" &
vbTab
Selection.TypeParagraph
ActiveDocument.Save
ActiveWindow.Close
Selection.Font.Size = 36
Selection.Font.Bold = wdToggle
ActiveDocument.MailMerge.MainDocumentType =
wdFormLetters
ActiveDocument.MailMerge.OpenDataSource
Name:="Z:\data\let.txt", _
ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="",
WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="",
SQLStatement:="", SQLStatement1 _
:=""
ActiveDocument.MailMerge.EditMainDocument
ActiveDocument.MailMerge.Fields.Add
Range:=Selection.Range, Name:="First"
Selection.TypeParagraph
ActiveDocument.MailMerge.Fields.Add
Range:=Selection.Range, Name:="Last"
SendKeys "~"

ActivePrinter = "OKI"

With ActiveDocument.MailMerge
.Destination = wdSendToPrinter
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With

ActivePrinter = "HP Color LaserJet 2500 PCL 6"

ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Application.ScreenUpdating = True
Application.Quit

End Sub



Can you spot the problem?

Sincere thanks as before,
 
G

Graham Mayor

Just a guess but Pause:=True may have something to do with it?

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Kenneth

Just a guess but Pause:=True may have something to do with it?

Hi Graham,

When I rem out the pause nothing at all happens, that is, no
print dialog, and no printing.

I was of the understanding that the SendKeys "~" would
"Push the button" on the print dialog, but now, for some
reason, that is not happening.

Any other thoughts on this?

Sincere thanks,
 
G

Graham Mayor

I have tested this macro (albeit with a different template and data file)
and it works as it stands. Do you have a default printer set in Windows and
is it a printer that is connected to a printer port and not to file?

Where did you rem out the pause?
It should have been at
.Execute 'Pause:=True

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Kenneth

I have tested this macro (albeit with a different template and data file)
and it works as it stands. Do you have a default printer set in Windows and
is it a printer that is connected to a printer port and not to file?

Where did you rem out the pause?
It should have been at
.Execute 'Pause:=True

Hi Graham,

I do have a default printer set, but it is not the one that
my macro prints to. I do not print to file.

I remmed out the .Execute 'Pause:=True and found that
nothing happened, that is, no print dialog opened and no
printing occurred.

I then re-created the macro (by recording) as I moved
through every step finally clicking the print dialog box to
print. When I looked at the code that had been recorded, the
pause had been inserted. And, that is the version you have
seen.

When I ran it, rather than printing, it behaved as I have
described before, the print dialog opened as it should, but
I had to manually click to print.

And finally, I started the new thread because I did not know
that you had further thoughts and I was hoping to get this
resolved if I could.

I sincerely appreciate your assistance, and, of course, will
stick to this thread.

Thanks again,
 
G

Graham Mayor

There is no code in your macro to change printers?

I have tested your code (changing only the templatename and the data file)
and it works here without pause straight to the default printer.

Strip out some of the extra stuff the recorder adds and then you get the
following to which (as this appears to be a label merge), the appropriate
document type and the propagation to the other labels of the inserted data
has been added.

Documents.Add Template:= "F:\Templates\Label 4x2.dot"
Selection.Font.Size = 36
Selection.Font.Bold = True
With ActiveDocument.MailMerge
.MainDocumentType = wdMailingLabels
.OpenDataSource Name:= "Z:\Data\let.txt"
.EditMainDocument
.Fields.Add Range:=Selection.Range, Name:="First"
WordBasic.MailMergePropagateLabel
.Destination = wdSendToPrinter
.SuppressBlankLines = True
.Execute
End With

As for having further thoughts, I am undoubtedly in a different time zone to
you (Eastern Europe), hence I may not respond when you expect. The regular
contributors here will jump in if they have anything to offer - but for
myself, I am fast running out of ideas. I would suggest that you look at
your template to see what is happening there, and to your printer
properties - for the macro works. This macro (now) puts the firstname field
from the data file into a table (the template), formats that field as 36
point bold and (now copies that field to all the other cells before) it
merges to the ActivePrinter. If you want to know how to change the active
printer, see http://www.gmayor.com/fax_from_word.htm

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Kenneth

There is no code in your macro to change printers?

I have tested your code (changing only the templatename and the data file)
and it works here without pause straight to the default printer.

Strip out some of the extra stuff the recorder adds and then you get the
following to which (as this appears to be a label merge), the appropriate
document type and the propagation to the other labels of the inserted data
has been added.

Documents.Add Template:= "F:\Templates\Label 4x2.dot"
Selection.Font.Size = 36
Selection.Font.Bold = True
With ActiveDocument.MailMerge
.MainDocumentType = wdMailingLabels
.OpenDataSource Name:= "Z:\Data\let.txt"
.EditMainDocument
.Fields.Add Range:=Selection.Range, Name:="First"
WordBasic.MailMergePropagateLabel
.Destination = wdSendToPrinter
.SuppressBlankLines = True
.Execute
End With

As for having further thoughts, I am undoubtedly in a different time zone to
you (Eastern Europe), hence I may not respond when you expect. The regular
contributors here will jump in if they have anything to offer - but for
myself, I am fast running out of ideas. I would suggest that you look at
your template to see what is happening there, and to your printer
properties - for the macro works. This macro (now) puts the firstname field
from the data file into a table (the template), formats that field as 36
point bold and (now copies that field to all the other cells before) it
merges to the ActivePrinter. If you want to know how to change the active
printer, see http://www.gmayor.com/fax_from_word.htm

Hi Graham,

Here is the code that I am using:

Sub NameTagsFirst()
'
' NameTagsFirst Macro
' Macro created 5/30/2002 by Kenneth Sole
'
'
Documents.Add Template:= _
"F:\Templates\Label 4x2.dot" _
, NewTemplate:=False, DocumentType:=0

With ActiveDocument.PageSetup
.TopMargin = InchesToPoints(0.7)
End With

Documents.Open FileName:="Z:\Data\let.txt",
ConfirmConversions:=False, ReadOnly:= _
False, AddToRecentFiles:=False,
PasswordDocument:="", PasswordTemplate:= _
"", Revert:=False, WritePasswordDocument:="",
WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto
Selection.TypeText Text:="First" & vbTab
Selection.TypeParagraph
ActiveDocument.Save
ActiveWindow.Close

Selection.Font.Size = 36
Selection.Font.Bold = wdToggle

ActiveDocument.MailMerge.MainDocumentType =
wdFormLetters
ActiveDocument.MailMerge.OpenDataSource
Name:="Z:\data\let.txt", _
ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="",
WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="",
SQLStatement:="", SQLStatement1 _
:=""
ActiveDocument.MailMerge.EditMainDocument
ActiveDocument.MailMerge.Fields.Add
Range:=Selection.Range, Name:="First"

ActivePrinter = "OKI"

With ActiveDocument.MailMerge
.Destination = wdSendToPrinter
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With

.Execute Pause:=True


End With


ActivePrinter = "HP Color LaserJet 2500 PCL 6"

ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Application.ScreenUpdating = True
Application.Quit


End Sub


It sets the active printer to "OKI" and then at the end,
sets back to a sheet printer.

I will certainly experiment with the stripped down code you
suggest, and as before, offer my sincere thanks,
 
K

Kenneth

On Thu, 28 Sep 2006 15:17:58 +0300, "Graham Mayor"

Hi Graham,

(With apologies if this is a duplicate...)

Below is my stripped down code as per your suggestion. It
runs with the Run Time Error 438 "Object doesn't support
this property or method on the line I have marked.


Sub Macro8()
'
' NameTagsFirst Macro
' Macro created 5/30/2002 by Kenneth Sole
'
'
Documents.Add Template:="F:\Templates\Label 4x2.dot"

ActivePrinter = "OKI"

Selection.Font.Size = 36
Selection.Font.Bold = True

With ActiveDocument.MailMerge
.MainDocumentType = wdMailingLabels
.OpenDataSource Name:="Z:\data\let.txt"
.EditMainDocument
.Fields.Add Range:=Selection.Range, Name:="First".Destination = wdSendToPrinter
.SuppressBlankLines = True
.Execute
End With

ActivePrinter = "HP Color LaserJet 2500 PCL 6"
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Application.ScreenUpdating = True
Application.Quit

End Sub


Thanks for any further help,
 
G

Graham Mayor

Is this Word 2003? What reference libraries do you have checked in the vba
editor (Tools > References) Make sure the Microsoft Word 11 and Microsoft
Office 11 object libraries are checked.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Kenneth

Is this Word 2003? What reference libraries do you have checked in the vba
editor (Tools > References) Make sure the Microsoft Word 11 and Microsoft
Office 11 object libraries are checked.

Hi Graham,

I am certainly sorry that I did not think to mention this
earlier, but I am running Word 2000 SP3.

The current checked References are:

Visual Basic for Applications
MS Word 9.0 object library
Ole Automation
MS Office 9 object library

Thanks again,
 
G

Graham Mayor

It should still work with Word 2000, though I do not have the facility to
check it. Sorry.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

Leave it until Monday when all the under-utilised programmers are back at
their desks and post the question in the vba general newsgroup. Ensure you
mention the Word version and list the code samples. There are undoubtedly
better programmers than me frequenting there and some will have Word 2000
available. If you are using NNTP access (http://www.gmayor.com/MSNews.htm )
then you can cross post to the mailmerge newsgroup (by putting both
addresses in the send to box, separated by a comma).

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Kenneth

Leave it until Monday when all the under-utilised programmers are back at
their desks and post the question in the vba general newsgroup. Ensure you
mention the Word version and list the code samples. There are undoubtedly
better programmers than me frequenting there and some will have Word 2000
available. If you are using NNTP access (http://www.gmayor.com/MSNews.htm )
then you can cross post to the mailmerge newsgroup (by putting both
addresses in the send to box, separated by a comma).

Hi Graham,

Sincere thanks for the suggestions, and for your past
efforts,
 
G

Graham Mayor

You are welcome

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


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

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