Thread: Print File
View Single Post
  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default Print File

You can also use the dir() function to test for existence.

myDocName = "C:\my documents\word\document1.doc"

becomes

myDocName = "c:\SymmcoPrograms\" & TextBox1.Value & "\" & ComboBox1.Value _
& "\" & ComboBox3.Value)



aftamath wrote:

Here's my code.
set fs = CreateObject("Scripting.FileSystemObject")

If ComboBox3.Value < "" Then
If fs.FileExists("c:\SymmcoPrograms\" & TextBox1.Value & "\" &
ComboBox1.Value _
& "\" & ComboBox3.Value) = True Then
ActiveWorkbook.FollowHyperlink Address:="c:\SymmcoPrograms\" &
TextBox1.Value _
& "\" & ComboBox1.Value & "\" & ComboBox3.Value, NewWindow:=False
Else
MsgBox "Cannot Find Specified Document"
End If
End If

I want to replace the hyperlink section with a command to print the file in
the FileExists argument.

"Dave Peterson" wrote:

I'm not sure how you would.

But I saved this from a previous post.

Option Explicit
Sub testme()

'Dim WDApp As Word.Application
'Dim WDDoc As Word.Document
Dim WDApp As Object
Dim WDDoc As Object
Dim myDocName As String
Dim WordWasRunning As Boolean
Dim testStr As String

myDocName = "C:\my documents\word\document1.doc"

testStr = ""
On Error Resume Next
testStr = Dir(myDocName)
On Error GoTo 0
If testStr = "" Then
MsgBox "Word file not found!"
Exit Sub
End If

WordWasRunning = True
On Error Resume Next
Set WDApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set WDApp = CreateObject("Word.Application")
WordWasRunning = False
End If

WDApp.Visible = True 'at least for testing!

Set WDDoc = WDApp.documents.Open(Filename:=myDocName)
WDDoc.PrintOut '.printPreview while testing???
WDDoc.Close savechanges:=False

If WordWasRunning Then
'leave it running
Else
WDApp.Quit
End If

Set WDDoc = Nothing
Set WDApp = Nothing

End Sub

aftamath wrote:

How do I use a FileSytemObject in VBA code to print a word document from excel.


--

Dave Peterson


--

Dave Peterson