• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA search file on disk and print it

Fila

New Member
Can you help me please creating a macro with search file from disk, look in: C:\Etikety\Stitky\. I search a name which contain in cell C2 and file type is .lbe
When file found print it. I would implemate this part of code into this code. Thanks for answer.
Code:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub zadat()
    Dim reg, check As String
    Dim i, j, done As Integer
    reg = Cells(2, 3).Value
    check = Cells(4, 3).Value

    If check = "True" Then
      i = 2
      j = 1
      done = 0

      Do While Sheets("data").Cells(i, j) <> ""
          If Sheets("data").Cells(i, j) = reg Then
            done = Sheets("data").Cells(i, j + 3)
            done = done + 1
            Sheets("data").Cells(i, j + 3) = done
            Exit Do
          End If
          i = i + 1
      Loop
    Else
      MsgBox ("Chyba, oprav!!!")
    End If

    Cells(3, 3) = ""
    Cells(3, 3).Select
    ActiveWindow.ScrollRow = Cells(1, 1).Row
End Sub
 
I try this part of code, works well but i need search name from cell "C2" and here is a file name. I would like to implemate this code with my code. thx for help

Code:
OptionExplicit

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
                        ByVal hwnd As Long, _
                        ByVal lpOperation As String, _
                        ByVal lpFile As String, _
                        ByVal lpParameters As String, _
                        ByVal lpDirectory As String, _
                        ByVal nShowCmd As Long) As Long

Public Function PrintThisDoc(formname As Long, FileName As String)
                On Error Resume Next
                Dim X As Long
                X = ShellExecute(formname, "Print", FileName, 0&, 0&, 3)
End Function

Sub testPrint()
    Dim printThis
    Dim strDir As String
    Dim strFile As String

    strDir = "C:\Users\Hello Baby\Desktop"
    strFile = "abc.pdf"

    printThis = PrintThisDoc(0, strDir & "\" & strFile)
End Sub
 
How are you going to get Excel to open a file with an extension of .lbe

this part of code works well.

strDir = "C:\Etikety\Stitky"
strFile = "157.130-00.lbe"

lbe is extension of Labelstar Plus, program for labels.
 
So if file name to search is contained in C2.

Change strFile = "string" to strFile = Range("C2").Value

If C2 does not contain ".lbe" portion you can concatenate it.
strFile = Range("C2").Value & ".lbe"
 
So if file name to search is contained in C2.

Change strFile = "string" to strFile = Range("C2").Value

If C2 does not contain ".lbe" portion you can concatenate it.
strFile = Range("C2").Value & ".lbe"


Thank you now I have 2 code which works well.
Please would someone be so kind to me and merged them into one functional code? The second code must be before Else in first code. Thx for your time

1. code

PublicDeclareSub Sleep Lib "kernel32" (ByVal dwMilliseconds AsLong)

Sub zadat()
Dim reg, check AsString
Dim i, j, done AsInteger
reg = Cells(2, 3).Value
check = Cells(4, 3).Value

If check = "True"Then
i = 2
j = 1
done = 0

DoWhile Sheets("data").Cells(i, j) <> ""
If Sheets("data").Cells(i, j) = reg Then
done = Sheets("data").Cells(i, j + 3)
done = done + 1
Sheets("data").Cells(i, j + 3) = done
ExitDo
EndIf
i = i + 1
Loop
Else
MsgBox ("Chyba, oprav!!!")
EndIf

Cells(3, 3) = ""
Cells(3, 3).Select
ActiveWindow.ScrollRow = Cells(1, 1).Row
EndSub


2. code

Option Explicit
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Public Function PrintThisDoc(formname As Long, FileName As String)
On Error Resume Next
Dim X As Long
X = ShellExecute(formname, "Print", FileName, 0&, 0&, 3)
End Function

Sub testPrint()
Dim printThis
Dim strDir As String
Dim strFile As String
strDir = "W:\Etikety\Štítky\Krabice"
strFile = Range("C2").Value & ".lbe"

printThis = PrintThisDoc(0, strDir & "\" & strFile)
End Sub
 
lbe is extension of Labelstar Plus, program for labels.


Also

The LBE file type is primarily associated with 'Life Balance' by Llamagraphics, Inc.. Stores a subset of the information in an .LBD file in an XML-based format suitable for interchange with other users of Life Balance.

Possible conflict with the OS
 
Back
Top