powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / Можно ли через VBA настроить принтер?
15 сообщений из 15, страница 1 из 1
Можно ли через VBA настроить принтер?
    #32621574
Gotar
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
См сабж....

Можно ли по средством кода в VBA установить новый принтер?
...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32621604
Фотография big-duke
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
так настроить или добавить ?
имхо самое простое это вызвать соотв аплет панели управления
есть и api PrintDialog .
...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32621607
Gotar
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
добавить
...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32621636
Фотография big-duke
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
вот что пишет Апплеман

AddPrinter

VB Declaration

Declare Function AddPrinter& Lib "winspool.drv" Alias "AddPrinterA" (ByVal pName_
As String, ByVal Level As Long, pPrinter As Byte)

Description

Adds a new printer to the system.

Use with VB

No problem.

Parameter Type/Description
pName String—The name of the server on which to install the print processor. Set to vbNullString for a local printer.
Level Long—Set to 2.
pPrinter Byte—First entry in a buffer containing a PRINTER_INFO_2 structure that has the fields pPrinterName, pPortName, pDriverName, pPrintProcessor and pDataType fields set to valid values. pPrinter can also be defined to be As PRINTER_INFO_2. The fields: Attributes, DefaultPriority, pComment, pDevMode, pLocation, pParameters, Priority, pSecurityDescriptor, pSepFile, pShareName, StartTime and UntilTime may also be set. Other fields should be left empty.
Return Value

Long—A handle to a new printer on success, zero on failure. Sets GetLastError.

Platform

Windows 95, Windows NT. Under NT, the caller must have sufficient privilege to configure printers on the specified server.

All of the material presented here is copyrighted by either Desaware or Macmillan. No part of this material may be used or reproduced in any fashion (except in brief quotations used in critical articles and reviews) without prior consent.

...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32621638
Фотография big-duke
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
если надо, то вот описание структуры

PRINTER_INFO_2

VB Declaration

Type PRINTER_INFO_2
pServerName As Long
pPrinterName As Long
pShareName As Long
pPortName As Long
pDriverName As Long
pComment As Long
pLocation As Long
pDevMode As Long
pSepFile As Long
pPrintProcessor As Long
pDatatype As Long
pParameters As Long
pSecurityDescriptor As Long ‘SECURITY_DESCRIPTOR
Attributes As Long
Priority As Long

DefaultPriority As Long
StartTime As Long
UntilTime As Long
Status As Long
cJobs As Long
AveragePPM As Long
End Type

Description

This structure contains detailed information on the printer.

Field Type/Description
pServerName Long—The address of a string buffer containing the name of the server for the printer. Zero or a null string for local printers.
pPrinterName Long—The address of a string buffer containing the name of the printer.
pShareName Long—The address of a string buffer containing the share name for the printer (valid only if printer is shared).
pPortName Long—The address of a string buffer containing the name of the printer port that it is connected to (multiple port names are separated by commas).
pDriverName Long—The address of a string buffer containing the name of the printer driver.
pComment Long—See PRINTER_INFO_1.
pLocation Long—The address of a string buffer containing the location of the printer.
pDevMode Long—The address of a DEVMODE structure that defines default settings for the printer.
pSepFile Long—The address of a string buffer containing the name of a file that is used to create separator pages to separate between print jobs.
pPrintProcessor Long—The address of a string buffer containing the name of the print processor for the printer.
pDatatype Long—The address of a string buffer containing the type of data used when recording the print job.
pParameters Long—The address of a string buffer containing default print-processor parameters.
pSecurityDescriptor Long—The address of a SECURITY_DESCRIPTOR structure for the printer. This member may be zero.
Attributes Long—Specifies printer attributes, can be any of the following: PRINTER_ATTRIBUTE_QUEUED, PRINTER_ATTRIBUTE_DEFAULT, PRINTER_ATTRIBUTE_DIRECT, PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST, PRINTER_ATTRIBUTE_ENABLE_BIDI, (Windows 95 only)
PRINTER_ATTRIBUTE_DIRECT, PRINTER_ATTRIBUTE_DEFAULT, PRINTER_ATTRIBUTE_SHARED, PRINTER_ATTRIBUTE_WORK_OFFLINE (Windows 95 only)
Priority Long—The priority that the spooler uses to route print jobs.
DefaultPriority Long—The default priority for print jobs on this printer.
StartTime, UntilTime Long—Specifies the earliest and latest time at which the printer will print a job (specified in minutes from 12:00 a.m.).
Status Long—Specifies printer status.In Windows NT, PRINTER_STATUS_PAUSED or PRINTER_STATUS_PENDING_DELETION.Any constant with the prefix PRINTER_STATUS_* under Windows 95.
cJobs Long—The number of jobs in the print queue for this printer.
AveragePPM Long—The average number of pages per minute for this printer.

...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32622396
Gotar
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Слушайте, а это прям в VBA делать? Я чет вообще неврубаюсь что к чему и с чем в этих кодах.....
...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32622439
Фотография big-duke
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
ну да прямо в vba.
вставляешь модуль, объявляешь функции, структуры и константы и вперед
в чеб трабл собственно ?
...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32622450
Gotar
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Трабла в том что чайник я, сижу вот с книжкой по VBA 2002 ну и в инете кое что подбираю....... 8))) щас сижу втыкаю что к чему 8)
...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32622463
Фотография big-duke
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32622515
Gotar
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
спс... Как там в песне было?

-Все мне ясно стало теперь.....

8)))

Спасибки.... Да кстати может еще подскажете как копировать папку с кучей файлов внуткри, ато в код 50 файлов на копирование загонять неохота 8)
...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32622633
Фотография big-duke
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
есть такая фишка FSO - file system object думаю через f2 и f1 разберешься
...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32622991
Gotar
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Блин проблемма -

Declare Function addprinter& Lib "winspool.drv" Alias "AddPrinterA" (ByVal pName As String, ByVal Level As Long, pPrinter As Byte)

на этой строчке выдает следующую ошибку :

Compile Error:
Only comments may appear after End Sub, End Function, or End properly

че за бадяга?

хотя перед етой строчкой только Sub tata(0 и все и никакое упоминание End Sub, End Function, or End properly......
...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32623283
Фотография Antonariy
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Declare пишется в начале модуля, перед объявлением прочих Sub и Function
...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32623325
Gotar
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Да, уже врубился, нашел вот такое вот чудо:

Public Type PRINTER_INFO_2
pServerName As Long 'String
pPrinterName As Long 'String
pShareName As Long 'String
pPortName As Long 'String
pDriverName As Long 'String
pComment As Long 'String
pLocation As Long 'String
pDevMode As Long ' DEVMODE
pSepFile As Long 'String
pPrintProcessor As Long 'String
pDatatype As Long 'String
pParameters As Long 'String
pSecurityDescriptor As Long 'SECURITY_DESCRIPTOR
Attributes As Long
Priority As Long
DefaultPriority As Long
StartTime As Long
UntilTime As Long
Status As Long
cJobs As Long
AveragePPM As Long
End Type

Public Type PRINTER_DEFAULTS
pDatatype As Long 'String
pDevMode As Long 'DEVMODE
DesiredAccess As Long
End Type


Public Declare Function AddPrinter Lib "winspool.drv" Alias "AddPrinterA" (ByVal pName As String, ByVal Level As Long, pPrinter As PRINTER_INFO_2) As Long
Public Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Public Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
Public Declare Function DeletePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long

Public Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As Long, ByVal lpString2 As String) As Long

Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const PRINTER_ACCESS_ADMINISTER = &H4
Public Const PRINTER_ACCESS_USE = &H8
Public Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
'
' This code adds a printer to a Windows NT/2000 server/workstation
'
' Written by Tony Edgecombe
' Tony.Edgecombe@frogmorecs.co.uk
' www.vbprint.com
' 22 Jan 2001
'
'


Function CreatePrinter(strServer As String, _
strPrinter As String, _
strPort As String, _
strDriver As String, _
strPrintProcessor As String) As Boolean

Dim hPrinter As Long
Dim pi2 As PRINTER_INFO_2
Dim bBuffer(1000) As Byte
Dim i

'*********************************************************************
' Initialise our buffer
'*********************************************************************

For i = 0 To UBound(bBuffer)
bBuffer(i) = 0
Next

'*********************************************************************
' Set the pointers to the string values in bBuffer
'*********************************************************************

pi2.pPrinterName = AddString(strPrinter, bBuffer)
pi2.pPortName = AddString(strPort, bBuffer)
pi2.pDriverName = AddString(strDriver, bBuffer)
pi2.pPrintProcessor = AddString(strPrintProcessor, bBuffer)

'*********************************************************************
' Default all other values to 0 (NULL)
'*********************************************************************

pi2.Attributes = 0
pi2.AveragePPM = 0
pi2.cJobs = 0
pi2.DefaultPriority = 0
pi2.pComment = 0
pi2.pDatatype = 0
pi2.pDevMode = 0
pi2.pLocation = 0
pi2.pParameters = 0
pi2.Priority = 0
pi2.pSecurityDescriptor = 0
pi2.pSepFile = 0
pi2.pServerName = 0
pi2.pShareName = 0
pi2.StartTime = 0
pi2.Status = 0
pi2.UntilTime = 0

'*********************************************************************
' Add the printer
' If success then close the returned handle
'*********************************************************************

hPrinter = AddPrinter(strServer, 2, pi2)
If hPrinter <> 0 Then
ClosePrinter (hPrinter)
CreatePrinter = True
Else
CreatePrinter = False
End If
End Function

Private Function AddString(strString As String, ByRef bBuffer() As Byte) As Long

'*********************************************************************
' AddString copies a string into a Byte array and returns a long
' pointer to that string
'*********************************************************************

Dim lngEnd As Long

lngEnd = UBound(bBuffer) + 1
Do
lngEnd = lngEnd - 1
Loop While (bBuffer(lngEnd) = 0 And lngEnd > 0)
lngEnd = lngEnd + 2

lstrcpy VarPtr(bBuffer(0)) + lngEnd, strString

AddString = VarPtr(bBuffer(0)) + lngEnd
End Function

Function RemovePrinter(strPrinter As String)
Dim hPrinter As Long
Dim pd As PRINTER_DEFAULTS

'*********************************************************************
' Create a PRINTER_DEFAULTS structure with the required access rights
'*********************************************************************

pd.pDatatype = 0
pd.pDevMode = 0
pd.DesiredAccess = PRINTER_ALL_ACCESS

'*********************************************************************
' Open the printer
'*********************************************************************

If OpenPrinter(strPrinter, hPrinter, pd) = 0 Then
RemovePrinter = False
Exit Function
End If

'*********************************************************************
' Remove it
'*********************************************************************

If DeletePrinter(hPrinter) = 0 Then
RemovePrinter = False
Exit Function
End If

'*********************************************************************
' Release the handle
'*********************************************************************

ClosePrinter (hPrinter)

RemovePrinter = True
End Function



Sub main()

'*********************************************************************
' Test call
'
' The parameters to CreatePrinter are:
'
' Server Name - Blank if local machine
' Printer Name - Must be unique
' Port Name - Port must be installed already
' Driver Name - Driver must be installed already
' Print Processor - Must be installed already
'
'*********************************************************************

MsgBox "Printer Creation: " & CreatePrinter("", "New Printer", "LPT1:", "HP LaserJet 1100 (MS)", "WinPrint")

'*********************************************************************
' Test Call
' Parameter is the name of the printer to delete
'
' For printers on another server use the UNC path ie \\Server\Printer
'*********************************************************************

MsgBox "Printer Deletion: " & RemovePrinter("New Printer")

End Sub

Написано под НТ, я делаю под XP... из за малеького багажа знания в VBA не врубаюсь что править нада... при запуске проги вылетает два месаджбока адд - фальс делит - фальс...

ничего не создается...

подскажите что где править....
...
Рейтинг: 0 / 0
Можно ли через VBA настроить принтер?
    #32623924
Gotar
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Мда - тормоз ето судьба 8)))))))

MsgBox "Printer Creation: " & CreatePrinter("", "Имя принтера", "Порт", "Название принтера", "WinPrint")


Ето убираем или лочим MsgBox "Printer Deletion: " & RemovePrinter("New Printer")

Как круто! Все пашет!...
...
Рейтинг: 0 / 0
15 сообщений из 15, страница 1 из 1
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / Можно ли через VBA настроить принтер?
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]