Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Print File
How do I use a FileSytemObject in VBA code to print a word document from excel.
|
#2
|
|||
|
|||
Print File
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
|
|||
|
|||
Print File
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
|
|||
|
|||
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 |
#5
|
|||
|
|||
Print File
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
|
|||
|
|||
Print File
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 |
#7
|
|||
|
|||
Print File
Sorry, I didn't realize I said to print a word document in my initial
question. I meant that the code can call on any type of file and print it. I figured that since VBA can search a computer's file system for a file and write it to a text file, maybe it can print the file that it finds also. It could be anything, a PDF, BMP, DOC, XLS, DRG, etc. "Dave Peterson" wrote: 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 |
#8
|
|||
|
|||
Print File
For me, printing means opening the application and either clicking on the print
icon or using a menu system. And with all the variations of programs, I'm not sure if you could do this with generic code. Heck, there are enough programs that can open .bmp's, that I'm not even sure if the same code would work for that extension. Maybe someone else has a solution. aftamath wrote: Sorry, I didn't realize I said to print a word document in my initial question. I meant that the code can call on any type of file and print it. I figured that since VBA can search a computer's file system for a file and write it to a text file, maybe it can print the file that it finds also. It could be anything, a PDF, BMP, DOC, XLS, DRG, etc. "Dave Peterson" wrote: 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 -- Dave Peterson |
#9
|
|||
|
|||
Print File
Thanks Dave, I didn't think it could be done with VBA.
"Dave Peterson" wrote: For me, printing means opening the application and either clicking on the print icon or using a menu system. And with all the variations of programs, I'm not sure if you could do this with generic code. Heck, there are enough programs that can open .bmp's, that I'm not even sure if the same code would work for that extension. Maybe someone else has a solution. aftamath wrote: Sorry, I didn't realize I said to print a word document in my initial question. I meant that the code can call on any type of file and print it. I figured that since VBA can search a computer's file system for a file and write it to a text file, maybe it can print the file that it finds also. It could be anything, a PDF, BMP, DOC, XLS, DRG, etc. "Dave Peterson" wrote: 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 -- Dave Peterson |
#10
|
|||
|
|||
Print File
It might be able to be done--just not by me.
Good luck, aftamath wrote: Thanks Dave, I didn't think it could be done with VBA. "Dave Peterson" wrote: For me, printing means opening the application and either clicking on the print icon or using a menu system. And with all the variations of programs, I'm not sure if you could do this with generic code. Heck, there are enough programs that can open .bmp's, that I'm not even sure if the same code would work for that extension. Maybe someone else has a solution. aftamath wrote: Sorry, I didn't realize I said to print a word document in my initial question. I meant that the code can call on any type of file and print it. I figured that since VBA can search a computer's file system for a file and write it to a text file, maybe it can print the file that it finds also. It could be anything, a PDF, BMP, DOC, XLS, DRG, etc. "Dave Peterson" wrote: 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 -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
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) |