Print files

J

JT

This code will print only file;

CreateObject("Shell.Application").Namespace(0).ParseName("c:\Notes\Note1.snp").InvokeVerb ("&Print")

I am trying to print all snp files and i keep getting error message ("object
variable or With block variable not set"). What am i doing wrong?


Dim strPath As String
Dim strFilter As String

strPath = "c:\Notes\"
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)")

CreateObject("Shell.Application").Namespace(0).ParseName(strPath +
strFilter).InvokeVerb ("&Print")



Function ahtAddFilterItem(strFilter As String, _
strDescription As String, Optional varItem As Variant) As String

If IsMissing(varItem) Then varItem = "*.*"
ahtAddFilterItem = strFilter & _
strDescription & vbNullChar & _
varItem & vbNullChar
End Function
 
S

Stuart McCall

JT said:
This code will print only file;

CreateObject("Shell.Application").Namespace(0).ParseName("c:\Notes\Note1.snp").InvokeVerb
("&Print")

I am trying to print all snp files and i keep getting error message
("object
variable or With block variable not set"). What am i doing wrong?


Dim strPath As String
Dim strFilter As String

strPath = "c:\Notes\"
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)")

CreateObject("Shell.Application").Namespace(0).ParseName(strPath +
strFilter).InvokeVerb ("&Print")



Function ahtAddFilterItem(strFilter As String, _
strDescription As String, Optional varItem As Variant) As String

If IsMissing(varItem) Then varItem = "*.*"
ahtAddFilterItem = strFilter & _
strDescription & vbNullChar & _
varItem & vbNullChar
End Function

Although I'm unfamiliar with this method, it looks to me like this line:

strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)")

should be just:

strFilter = "*.snp"
 
D

Douglas J. Steele

You seem to be combining things that aren't intended to be combined!

The function ahtAddFilterItem appears to be the function from
http://www.mvps.org/access/api/api0001.htm at "The Access Web". It's
intended to be used with the rest of the code on that page, which is how to
invoke the standard Windows File Open or File Save dialogues. On the other
hand, the ParseName method is intended to create and returns a FolderItem
object that represents a specified item. I do not believe you can use
wildcards with it.

Try:

Dim strPath As String
Dim strFile As String

strPath = "c:\Notes\"
strFile = Dir(strPath & "*.snp")
Do While Len(strFile) > 0
CreateObject("Shell.Application").Namespace(0).ParseName(strPath &
strFile).InvokeVerb ("&Print")
strFile = Dir()
Loop
 
J

JT

Thank you but when i click on button the print window will pop up. Sense i
have 100 and more snp files in my folder, I have to click 100 times and more
on 'Print' button. How can i avoid that??? Thank you

Private Sub Command10_Click()
On Error GoTo Command10_Click_Error
Dim strPath As String
Dim strFilter As String

strPath = "C:\Notes\"
strFile = Dir(strPath & "*.snp")

Do While Len(strFile) > 0
CreateObject("Shell.Application").Namespace(0).ParseName(strPath &
strFile).InvokeVerb ("&Print")
strFile = Dir()
Loop

Command10_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
End Su
---------------------------------------------------------------------------------
 
D

Douglas J. Steele

If invoking the Print verb causes a dialog to appear, I don't think there's
anything you can do.
 

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

Similar Threads


Top