newbee2
Technical User
- Apr 21, 2002
- 85
- 0
- 0
Hi,
When I run the following part of code it returns an error at the strTemplatePath or states that the Template can't be found. It exists and its where its supposed to be for this application. This is a snippet of it. The code is part of a module, of which there are 4 to produce the automation of a report. All modules are Option explicit. The first module runs an access function, the second charts as gifs, the third selects a range on an Excel sheet, the forth takes the Range and pastes it into word. Each module is run indian file being called up from the one before. Data is saved to My Documents in a Named folder. Run on its own from the immediate window the code runs the next time it may not. Any Suggestion welcome.
Option Explicit
Sub WordStart()
'set up variables
Dim objWord As Word.Application
Dim objDocs As Object
Dim strShortDate As String
Dim strDoc As String
Dim strDocsPath As String
Dim strSaveName As String
Dim strSaveNamePath As String
Dim strTemplatePath As String
Dim strtest As String
Dim strtestfile As String
Dim strwordtemplate As String
Dim strmessagetitle As String
Dim strmessage As String
Dim blnSaveNameFail As Boolean
Dim strCompanyName As String
Dim intCount As Integer
Dim intreturn As Variant
'create word session
Set objWord = CreateObject("Word.Application"
objWord.Visible = True
'the paths for templates and documents are hard coded.
strTemplatePath = "C:\My Documents" & "\"
strwordtemplate = strTemplatePath & "SalesChart.dot"
strDocsPath = "C:\My Documents\EmailSalesReport" & "\"
Debug.Print "Docs path: " & strDocsPath
'this date string is used in creating the letter save name.
strShortDate = Format(Date, "dd-MMM-yyyy"
'check for existance of template in folder
'exit if not found
strtestfile = Nz(Dir(strwordtemplate))
If strtestfile = "" Then
MsgBox strwordtemplate & " template not found; can't create Chart."
Exit Sub
End If
Regards
Bill
When I run the following part of code it returns an error at the strTemplatePath or states that the Template can't be found. It exists and its where its supposed to be for this application. This is a snippet of it. The code is part of a module, of which there are 4 to produce the automation of a report. All modules are Option explicit. The first module runs an access function, the second charts as gifs, the third selects a range on an Excel sheet, the forth takes the Range and pastes it into word. Each module is run indian file being called up from the one before. Data is saved to My Documents in a Named folder. Run on its own from the immediate window the code runs the next time it may not. Any Suggestion welcome.
Option Explicit
Sub WordStart()
'set up variables
Dim objWord As Word.Application
Dim objDocs As Object
Dim strShortDate As String
Dim strDoc As String
Dim strDocsPath As String
Dim strSaveName As String
Dim strSaveNamePath As String
Dim strTemplatePath As String
Dim strtest As String
Dim strtestfile As String
Dim strwordtemplate As String
Dim strmessagetitle As String
Dim strmessage As String
Dim blnSaveNameFail As Boolean
Dim strCompanyName As String
Dim intCount As Integer
Dim intreturn As Variant
'create word session
Set objWord = CreateObject("Word.Application"
objWord.Visible = True
'the paths for templates and documents are hard coded.
strTemplatePath = "C:\My Documents" & "\"
strwordtemplate = strTemplatePath & "SalesChart.dot"
strDocsPath = "C:\My Documents\EmailSalesReport" & "\"
Debug.Print "Docs path: " & strDocsPath
'this date string is used in creating the letter save name.
strShortDate = Format(Date, "dd-MMM-yyyy"
'check for existance of template in folder
'exit if not found
strtestfile = Nz(Dir(strwordtemplate))
If strtestfile = "" Then
MsgBox strwordtemplate & " template not found; can't create Chart."
Exit Sub
End If
Regards
Bill