Program to Automatically Save Word File

M

maperalia

I have a program that saves as excel and word file with the same filename
(see program below). The excel file is being saved without problem, however,
the word file it is not working at all.

Could you please help me with this matter?.. I think that even the
description I wrote under the word program are completely wrong.

Thanks.
Maperalia


‘*****Start of Program*********
Option Explicit

Public Sub OpenWordAndUpdateLinks()
SaveExcelTemplateAsSaveAs
SaveWordTemplatelAsSaveAs

End Sub

Sub SaveExcelTemplateAsSaveAs()

Dim WO As String
Dim grdprp As String
Dim sFilename As String
Dim Progname As String
Dim Filename As String
Dim myDateTime As String

WO = Worksheets("summary BLR").Range("M10")
myDateTime = Format(Worksheets("summary BLR").Range("M9").Value,
"yyyymmdd")
Filename = "" & WO & "_" & myDateTime & ""
Progname = "C:\Form\" & Filename & ".xls"
ActiveWorkbook.SaveCopyAs Progname
End Sub

'***********OPEN THE TEMPLATE WORD FILE AND SAVE
AS****************************
Sub SaveWordTemplatelAsSaveAs()
Dim wordApp As Object
Dim fNameAndPath As String
Dim Filename As String
Dim WO As String
Dim myDateTime As String

WO = Document("Page 1,Section 1",At 2.1").Range("ln 1,col 2 to ln 1, col
19")
myDateTime = Document("Page 1,Section 1",At 2").Range("ln 2,col 7 to ln
2,col 19")

fNameAndPath = "C:\Word\Template.doc"
Set wordApp = CreateObject("Word.Application")
wordApp.Documents.Open (fNameAndPath)
wordApp.Visible = True
wordApp.Activate

Filename = "" & WO & "_" & myDateTime & ""
Progname = "C:\Form\" & Filename & ".doc"
ActiveDocument..SaveCopyAs Progname



End Sub
'**********************************************************

‘*****End of Program*********
 
H

Helmut Weber

Hi Maperalia,
Dim WO As String
WO = Document("Page 1,Section 1",At 2.1").Range("ln 1,col 2 to ln 1, col
19")

the way You are trying to create a filename is a nightmare!
Don't!

Besides that, You can't use " for "inch" without getting
problems, as " is used as string delimiter.

Don't know where to begin.
Start from scratch, sorry to say so.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

maperalia

Helmut;
Could you please advice me a friendly way to do this program?..

Best regards.
Maperalia
 
H

Helmut Weber

Hi Maperalia,

I assume, You want to control Word from Excel,
and You got all working for an Excel-workbook.

You have a string like: "c:\test\4000\Projekt02"

Add ".xls" for the workbook name.
Add ".doc" for the document name.
' ---
Dim sNamePart As String
Dim sNameExcl As String
Dim sNameWord As String
sNamePart = "c:\test\4000\Projekt02"
sNameExcl = sNamePart & ".xls"
sNameWord = sNamePart & ".doc"
' --- plus
' reference to word set
' word already running
' only one word doc open
Dim oWrd As Word.Application
Dim oDcm As Word.Document
Set oWrd = GetObject(, "Word.Application") ' Comma !!!
Set oDcm = oWrd.ActiveDocument
oDcm.SaveAs sNameWord

First simply try to save a word doc from excel at first.

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 

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