Macro file program help

M

Manoj Shah

I like to copy a block from word document and save as another word document naming person's account number document. If that file name is present then need to append in tnat document. I have made program but it gives error at .FileName = ![AccNo].doc. I don't know how to take input in to file name

' fileNewOld Macr
' Macro recorded 1/3/2004 by Manoj Sha

Selection.Cop
'Define patient's account numbe
Dim AccNo As Strin
AccNo = InputBox("Please write Account number", "Account Number"

'Find file with account number if 0, open new blank documen
Set fs = Application.FileSearc
With f
.LookIn = "C:\Documents and Settings\Manoj\My Documents\Manoj\
.FileName = ![AccNo].do
If .Execute = 0 The
Documents.Add DocumentType:=wdNewBlankDocumen
Selection.PasteAndFormat (wdPasteDefault
ActiveDocument.SaveAs FileName:=![AccNo].doc, FileFormat:=wdFormatDocument,
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False,
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=
Fals
WordBasic.EditOfficeClipboar
CommandBars("Task Pane").Visible = Fals
ActiveWindow.Clos

Els
Documents.Open FileName:=![AccNo].doc, ConfirmConversions:=False, ReadOnly:=
False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:=
"", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="",
Format:=wdOpenFormatAuto, XMLTransform:="
Selection.EndKey Unit:=wdStor
Selection.TypeParagrap
Selection.PasteAndFormat (wdPasteDefault
ActiveDocument.Sav
ActiveWindow.Clos
WordBasic.EditOfficeClipboar
CommandBars("Task Pane").Visible = Fals
End I
End Wit

Thank you
 
J

Jay Freedman

Hi, Manoj,

The String variable named AccNo contains the account number as it was
entered by the user. You need to attach the string ".doc" to the end
of it, and use that as the file name. The syntax should be

.FileName = AccNo & ".doc"

Manoj Shah said:
I like to copy a block from word document and save as another word document naming person's account number document. If that file name is present then need to append in tnat document. I have made program but it gives error at .FileName = ![AccNo].doc. I don't know how to take input in to file name.

' fileNewOld Macro
' Macro recorded 1/3/2004 by Manoj Shah
'
Selection.Copy
'Define patient's account number
Dim AccNo As String
AccNo = InputBox("Please write Account number", "Account Number")

'Find file with account number if 0, open new blank document
Set fs = Application.FileSearch
With fs
.LookIn = "C:\Documents and Settings\Manoj\My Documents\Manoj\"
.FileName = ![AccNo].doc
If .Execute = 0 Then
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdPasteDefault)
ActiveDocument.SaveAs FileName:=![AccNo].doc, FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
WordBasic.EditOfficeClipboard
CommandBars("Task Pane").Visible = False
ActiveWindow.Close

Else
Documents.Open FileName:=![AccNo].doc, ConfirmConversions:=False, ReadOnly:= _
False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
"", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto, XMLTransform:=""
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.PasteAndFormat (wdPasteDefault)
ActiveDocument.Save
ActiveWindow.Close
WordBasic.EditOfficeClipboard
CommandBars("Task Pane").Visible = False
End If
End With

Thank you
 
M

Manoj Shah

Dear Jay:

Thank you, it worked.

Manoj Shah

----- Jay Freedman wrote: -----

Hi, Manoj,

The String variable named AccNo contains the account number as it was
entered by the user. You need to attach the string ".doc" to the end
of it, and use that as the file name. The syntax should be

.FileName = AccNo & ".doc"

Manoj Shah said:
I like to copy a block from word document and save as another word document naming person's account number document. If that file name is present then need to append in tnat document. I have made program but it gives error at .FileName = ![AccNo].doc. I don't know how to take input in to file name.
' fileNewOld Macro
' Macro recorded 1/3/2004 by Manoj Shah
'
Selection.Copy
'Define patient's account number
Dim AccNo As String
AccNo = InputBox("Please write Account number", "Account Number")
'Find file with account number if 0, open new blank document
Set fs = Application.FileSearch
With fs
.LookIn = "C:\Documents and Settings\Manoj\My Documents\Manoj\"
.FileName = ![AccNo].doc
If .Execute = 0 Then
Documents.Add DocumentType:=wdNewBlankDocument
Selection.PasteAndFormat (wdPasteDefault)
ActiveDocument.SaveAs FileName:=![AccNo].doc, FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
WordBasic.EditOfficeClipboard
CommandBars("Task Pane").Visible = False
ActiveWindow.Close
Documents.Open FileName:=![AccNo].doc, ConfirmConversions:=False, ReadOnly:= _
False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
"", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto, XMLTransform:=""
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.PasteAndFormat (wdPasteDefault)
ActiveDocument.Save
ActiveWindow.Close
WordBasic.EditOfficeClipboard
CommandBars("Task Pane").Visible = False
End If
End With
Thank you
 

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