以下代码是我以前的同事写的,我本人也才开始学VBA没两天,但是同事想要实现按照文件名的顺序去打印 文件名是数字的,但是数字大小是随机,如何设置按照文件名从小到大去打印呢? 说实话 这个代码还没看懂呢
Declare Function ShellExecute Lib"shell32.dll" Alias "ShellExecuteA" _ (ByVal hwnd As Long, ByVal lpszOp AsString, _ ByVal lpszFile As String, ByVal lpszParamsAs String, _ ByVal LpszDir As String, ByVal FsShowCmd AsLong) _ As Long Private Declare Sub Sleep Lib"kernel32" (ByVal dwMilliseconds As Long) Sub prin() Dim WS As Worksheet Dim Rows As Long Dim i As Long Dim fpath As String Dim fname As String Set WS = Worksheets("Sheet1") fpath = Application.ActiveWorkbook.Path& "\" Rows = WS.UsedRange.Rows.Count Application.ScreenUpdating = False For i = 2 To Rows fname= fpath & WS.Cells(i, 1) & ".pdf" 'ShellExecute Application.hwnd, "print", "C:\Print\258.pdf","", "", SW_HIDE '自己改打印的文件路径 ShellExecuteApplication.hwnd, "print", fname, "", "", SW_HIDE sleep8000 Next Application.ScreenUpdating = True End Sub
|