Home |
Search |
Today's Posts |
|
#1
![]() |
|||
|
|||
![]()
How do I use a FileSytemObject in VBA code to print a word document from excel.
|
#2
![]() |
|||
|
|||
![]()
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 |
#3
![]() |
|||
|
|||
![]()
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 |
#4
![]() |
|||
|
|||
![]()
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 |
#5
![]() |
|||
|
|||
![]()
When I declare myDocName as the filepath. Then tell it myDocName.Print, an
error pops up for Object Required. "Dave Peterson" wrote: 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 |
#6
![]() |
|||
|
|||
![]()
Yep.
But it's printing using this line: WDDoc.PrintOut This works because earlier, it used this: Set WDDoc = WDApp.documents.Open(Filename:=myDocName) All of the code in that original post was important. aftamath wrote: When I declare myDocName as the filepath. Then tell it myDocName.Print, an error pops up for Object Required. "Dave Peterson" wrote: 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 -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Links picking up values from an older version of linked file | Links and Linking in Excel | |||
How do I print the read-only status of Excel file? | Excel Discussion (Misc queries) | |||
How do you have the file path print on all pages? | Excel Worksheet Functions | |||
When I try to print from excel, the computer looks for a file in t | Excel Discussion (Misc queries) | |||
print to file | Excel Discussion (Misc queries) |