Daq with excel vba
Hello,
I'm working with Excel VBA and I have a 6024E card. I'd like to know where I can download the CW DAQ 3.0.1 and if there is a documentation describing the functionality of the CW DAQ.
With kind regards
Alexander Heß
Hello Alex,
you are able to use 3 different drivers for the device.
DAQmx,Traditional DAQ or DAQmx Base.
I didnt found any 3.0.1 version.
Only a 3.1 version of the DAQmx Base driver.
http://joule.ni.com/nidu/cds/view/p/id/970/lang/de
Here a link to the DAQcard overview with the latest driver software: http://zone.ni.com/devzone/cda/tut/p/id/6910#eseries
Kind regards,
Elmar
Similar Messages
-
Getting clusters from LabVIEW ActiveX Server with Excel/VBA
Hello,
my colleague and I are trying to control a LV from Excel (VBA) by ActiveX.
I.E.:
We do something like :
Set LV = createObject("LabVIEW.Application")
Set VI = LV.GetVIReference("Path_to_VI")
ParamNames(0) = "Input1"
ParamNames(1) = "Input2"
ParamNames(2) = "Output"
ParamValues(0) = 1
ParamValues(1) = 3.1415
Call VI.Call(ParamNames,ParamValues)
msgbox("output =" & ParamVals(2))
This works perfectly for simple data types (int, double, float, string, etc )
Now we need to transfer more complex structures, which are originaly LV-clusters.
But we did not find any clue on how do that (especially receive clusters) in the help or on the internet.
Is there any chance to succeed ???
TIA,
ThomasActually, working with clusters is really really easy. Through the magic of - well something - a cluster in LV comes out in the VBA environment as an array of variants. There was an activex example that shipped with V7.1 that showed this very thing. I couldn't find them in V8 so here is the 7.1 stuff.
Check out the macros in the Excel spreadsheet... This show running the VI in the development environment, but if this looks interesting I can fill you in on how to make it work in an executable.
Mike...
Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion
"... after all, He's not a tame lion..."
Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps
Attachments:
freqresp.xls 49 KB
Frequency Response.llb 155 KB -
Find an highlight text with Excel vba an Acobat XI Pro
Hello,
i want to write a VBA Script to search for and highlight text.
Until now my Script open the PDF and search for text. But how can i highlight it ?
Thank you.
Axel
My Code :
Sub OpenPDFPageView()
Dim PDFApp As AcroApp
Dim PDFDoc As AcroAVDoc
Dim PDFPageView As AcroAvPageView
Dim PDFPath As String
Dim DisplayPage As Integer
PDFPath = "C:\Users\info_000\Desktop\test.pdf"
'Set the page you want to be displayed
DisplayPage = 1
'Initialize Acrobat by creating App object
Set PDFApp = CreateObject("AcroExch.App")
'Set AVDoc object
Set PDFDoc = CreateObject("AcroExch.AVDoc")
'Open the PDF
If PDFDoc.Open(PDFPath, "") = True Then
PDFDoc.BringToFront
'Maximize the document
Call PDFDoc.Maximize(True)
Set PDFPageView = PDFDoc.GetAVPageView()
'Go to the desired page
'The first page is 0
Call PDFPageView.GoTo(DisplayPage - 1)
'Set the page view of the pdf
Call PDFPageView.ZoomTo(2, 50)
End If
If PDFDoc.FindText("blabla", 1, 1, 1) = True Then
Debug.Print "gefunden"
call pdfdoc.
Else
Debug.Print "nicht gefunden"
End If
Set PDFApp = Nothing
Set PDFDoc = Nothing
On Error Resume Next
'Show the adobe application
PDFApp.Show
'Set the focus to adobe acrobat pro
AppActivate "Adobe Acrobat Pro"
End SubWith Acrobat Javascript you can search for words, retrieve the position of the found words, and add annotations at this positions.
-
How to use loop in VBAK table using BDC RFC connection through excel vba ?
Hello,
I am trying to extract data from VBAK table using rfc connection with Excel VBA. where i can able to pull data first time, when i tried to use the same set of code using loops, it throws an error like BAD INDEX.
Any help appreciated.Hello,
I am trying to extract data from VBAK table using rfc connection with Excel VBA. where i can able to pull data first time, when i tried to use the same set of code using loops, it throws an error like BAD INDEX.
Any help appreciated. -
Fill a PDF form via Excel (VBA) - Hide text box
Hi,
i already created a PDF form and also can fill the text boxes with Excel VBA.
Now i'm about to hide some fields if they are empty, but i have no clue how to.
My code to fill the fields is:
Fields("Title").Value = Worksheets(TabName).Cells(actCell, 4).Value
To hide a field the code should be similar, but i have no clue what statement i need to set.
I already tried:
Fields("Title").Visible = False
Fields("Title").Hide
Fields("Title").Hide = True
What else can i type to hide and unhide the fields?
Looking forward to hear from you.
Thanks a lot.Does the form have a provision to insert images (e.g. a Browse button)?
[topic moved to iOS subforum] -
Adobe Javascript from within Excel VBA
I have some limited experience with Excel VBA and Adobe Javascript separately, but have never tried to put them together. I am rather baffled by the use of “DoJavaScript” from within Excel VBA. I have a number of Illustrator JavaScripts that do various tasks (mostly measure and set properties on illustrator drawing objects to determine some geometric metrics). I wanted to run these scripts from within Excel VBA (they run without problem when directly called into Illustrator). My hope was to pass a few real numbers from VBA into the JavaScript before one ran to set some run parameters and then get a few real numbers back out from the JavaScript back into VBA. I cannot seem to get even the simple DoJavaScript command given in the Adobe VBscript reference to run. Reading other posts that seem somewhat related it is not clear if I am doing something very simple wrong, or if my understanding of the use of the DoJavaScript command is misguided. Anyone able to shed some light on this?
My last try was this simple test...almost directly from the Adobe reference:
Private Sub SetScale_CommandButton1_Click()
Set appRef = CreateObject("Illustrator.Application")
Set myNumberOfDocuments = appRef.DoJavaScript("documents.length;")
MsgBox myNumberOfDocuments
End Sub
I am really hoping to be able to run javascripts that are a few hundred lines long....but if I cannot even get something simple to go then I am about to give up on it.
Thanks for any suggestionsCarlos;
I am most grateful! ... I was stumped on that for hours, thought I had tried about every combinatory possible, and was about to give up on getting the DoJavaScript method to work. There are few examples of this on the web, so for anyone else who would like a bit more verbose example I post below is a simple VBA sub-routine that uses a javascript function to return the number of selected objects in the current active illustrator document and displays that number in a message box in excel. Simple example, but it was the sort if thing I was looking for all over the web before Carlos’ help.
Cheers,
Brian
Private Sub ObjectNum()
Set appRef = CreateObject("Illustrator.Application")
tmp$ = "function myfunction() {"
tmp$ = tmp$ + "var idoc = app.activeDocument;"
tmp$ = tmp$ + "var sel = idoc.selection;"
tmp$ = tmp$ + "var numobj = sel.length;"
tmp$ = tmp$ + "return numobj;};"
tmp$ = tmp$ + "myfunction();"
numobj = appRef.DoJavaScript(tmp$)
MsgBox numobj
End Sub -
Problem with controlling Annotations from Excel VBA
Hi,
I have a PDF document that has plenty of sticky notes attached to it. These sticky notes have been added by multiple authors on all pages of the document. I am trying to import the contents of these sticky notes, their author and the page number to an excel spreadsheet. I am using Excel 2007 and Acrobat Professional 9.0.
This is the code that I am currently using to import the sticky notes, but the problem that I am facing is that when I run the macro -
Same sticky note contents, author and page numbers are imported multiple times
Not all sticky notes are imported, only some of them appear in the final excel spreadsheet
When I compare the number of sticky notes to that in the original PDF file, the number is correct. But the content is repeated content and that is the reason why only some of the sticky notes are imported.
This is an activity that I need to do on regular basis and the number of sticky notes that I need to import to excel may range between 100 to 200. It is really difficult to do this task manually, so an excel VBA macro could prove really helpful.
Sub ImportComments_Click()
Dim Fpath As String
Dim WordObj As Object
Dim wbkOutput As Excel.Workbook
Dim iRow As Integer
Dim i, j, k As Integer
Dim lRet As Long
Dim objAcroAVDoc As New Acrobat.acroAVDoc
Dim objAcroPDDoc As Acrobat.AcroPDDoc
Dim numPages As Long
Dim lAnnotscnt As Long
Dim Subtype As String
Dim NumComments As Long
Dim AcroApp As Acrobat.AcroApp
Dim objAcroPDPage As Acrobat.AcroPDPage
Dim annot As Acrobat.AcroPDAnnot
Sheets("Defect Log").Select
Range("L3").Activate
Fpath = ActiveCell.Value
Sheets("Defect Log").Select
Range("A1").Activate
i = 0
Do While (Not (IsEmpty(ActiveCell.Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 1).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 2).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 3).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 4).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 5).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 6).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 7).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 8).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 9).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 10).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 11).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 12).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 13).Value)) Or Not (IsEmpty(ActiveCell.Offset(0, 14).Value)))
i = i + 1
ActiveCell.Offset(1, 0).Select
Loop
iRow = i + 1
Set wbkOutput = ActiveWorkbook
lRet = objAcroAVDoc.Open(Fpath, "")
Set objAcroPDDoc = objAcroAVDoc.GetPDDoc
numPages = objAcroPDDoc.GetNumPages()
Set objAcroPDPage = objAcroPDDoc.AcquirePage(0)
For k = 1 To numPages
lAnnotscnt = objAcroPDPage.GetNumAnnots()
For m = 0 To lAnnotscnt - 1
If lAnnotscnt = 0 Then Exit For
Set objAcroPDAnnot = objAcroPDPage.GetAnnot(m)
If (objAcroPDAnnot.GetContents <> "" And objAcroPDAnnot.GetSubtype = "Text") Then
Cells(iRow, 5).Value = k
Cells(iRow, 2).Value = objAcroPDAnnot.GetContents()
Cells(iRow, 11).Value = objAcroPDAnnot.GetTitle()
iRow = iRow + 1
End If
Next m
Set objAcroPDPage = objAcroPDDoc.AcquirePage(k)
Next k
lRet = objAcroAVDoc.Close(1)
Set objAcroAVDoc = Nothing
Set objAcroPDAnnot = Nothing
Set objAcroPDPage = Nothing
Set objAcroPDDoc = Nothing
End SubMake sure you are current with 9.x patches, just on general principles.
The code seems fine – nothing jumping out at me.
You can also look at using the JSObject methods and trying this via the JavaScript stuff – that will give you more access to the Annotation information…
From: Adobe Forums <[email protected]<mailto:[email protected]>>
Reply-To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
Date: Thu, 24 Nov 2011 04:25:12 -0800
To: Leonard Rosenthol <[email protected]<mailto:[email protected]>>
Subject: Problem with controlling Annotations from Excel VBA
Problem with controlling Annotations from Excel VBA
created by apreeti<http://forums.adobe.com/people/apreeti> in Acrobat SDK - View the full discussion<http://forums.adobe.com/message/4044740#4044740 -
Excel 2013 VBA Compatible with Excel 2010
Hello,
I am new at working with VBA and have a question regarding an excel sheet with a VBA macro inserted.
The sheet was created in Excel 2013 by another user, and my laptop runs Excel 2010. I get script errors when I run it, however on Excel 2013 it works fine.
My question is: Is there a way to make Excel 2010 work with Excel 2013 VBA scripts? Perhaps importing the library from Excel 2013 VBA to E-2010? Or perhaps a way to save a VBA script in E-2013 to be backwards compatible with E-2010?
Thank you all for your support.Open the workbook.
Select Tools > References...
The references that are in use have their check box ticked. They are all at the top of the list. Do any of those start with MISSING?
Regards, Hans Vogelaar (http://www.eileenslounge.com) -
Problem with SQL Query in Excel VBA
I am trying to retrieve data from a SQL table using Excel VBA. The query will only return data from the first field in the query. this is the code I am using:
objGroupConn.Open
Set objGroupCmd.ActiveConnection = objGroupConn
objGroupCmd.CommandText = "SELECT GroupName, GroupNotes, GroupTotal, ArrivalTime" _
& " FROM dbo.tblGroups" _
& " WHERE((tblGroups.VisitDate)= '" & vdate & "')"
objGroupCmd.CommandType = adCmdText
objGroupCmd.Execute
Set objGroupRecordset.ActiveConnection = objGroupConn
objGroupRecordset.Open objGroupCmd
ActiveSheet.Range("BN5").CopyFromRecordset (objGroupRecordset)
objGroupRecordset.Close
objGroupConn.Close
The query is asking for information from 4 fields and only returns GroupName. Any ideas?Hi GAMinTN,
I can't reproduce your problem, if I created the same table as yours, I can successfully retrieve the data from the table and copy to the specified range.
I recommend that you firstly check if the table in the database contains the proper data in all the 4 columns. Since the command text can be executed successfully and get the data of one column, it should be able to get the data from the other columns.
Also please debug your code, check if the objGroupRecordset contains the proper data, and try to execute the SQL statement directly in the Sql Server, make sure the SQL statement is correct.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Excel VBA to access sharepoint list without permission
Hi,
I do find solution to retrieve the SharePoint list from excel VBA but my problem now is on the SharePoint permission to the list.
I am developing this solution in excel because i don't want the particular user to access the list direct from the portal because the list contains some unique and confidential data. So what i did was created a new view in the portal with selected column
and i connect to the view from excel. So every time the user want to retrieve the data, he can run macro to refresh the data in the excel.
When i run the macro it can generate the list because i do have permission but if i run the same macro on the person machine, excel request for username and password because he don't have the permission to the list.
Are there any work around to allow the user to generate the data in excel without permission to the SharePoint list.
Thanks for the help.I've done this before using SQL Server Reporting Services integrated into SharePoint.
Using SSRS, create the report you want the end user to view. Then create a Report Subscription, emailing the end user (or putting it in a file share/Doc Lib) the report. If they want to run it interactively, you can enable caching on the report, which would
pull the report from the last time it was scheduled to run (the data would not be 'real time' in this case).
Trevor Seward
Follow or contact me at...
  
This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs. -
How to delete formula from cells and keep the values in Excel VBA
Hi,
In my Excel I have 15 columns. In column F which has a formula (INDEX MATCH), it has contains "RECEIVED" and "INTRANSIT". I need to filter the column F for all "RECEIVED" and then remove the formula from cells and
retain or keep the values that are already in the cells. something tricky and i'm not sure on how to work on this in Excel VBA.
Below is my initla VBA code:
I already have the codes on how to filter. kindly please help me on how to do this. thank you in advance.
Sub test_Click()
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
Dim lrow As Long
Set wb = ThisWorkbook
Set ws = wb.Sheets("Intransit_")
Application.ScreenUpdating = False
ws.AutoFilterMode = False
With ws
lrow = .Range("F" & Rows.Count).End(xlUp).Row
Set rng = .Range("A1:R" & lrow)
Debug.Print rng.Address
rng.AutoFilter Field:=6, Criteria1:="RECEIVED"
End With
Application.creenUpdting = True
End SubSolved.
Sub test_Click()
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
Dim lrow As Long
Dim rRec As Range
Dim btField As Byte
Set wb = ThisWorkbook
Set ws = wb.Sheets("Intransit_")
btField = 6
Application.ScreenUpdating = False
ws.AutoFilterMode = False
With ws
lrow = .Range("F" & Rows.Count).End(xlUp).Row
Set rng = .Range("A1:R" & lrow)
With rng
.AutoFilter Field:=btField, Criteria1:="RECEIVED"
On Error Resume Next
Set rRec = .SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
.AutoFilterMode = False
If Not rRec Is Nothing Then
With rRec
.Columns(btField).Value = .Columns(6).Value
End With
End If
End With
Application.ScreenUpdating = True
End Sub -
How to get Data from SAP B1 through Journal Entries objects (Excel VBA)
Hi Genius
i had try to login SAB B1 thorugh MS Excel VBA code and it worked well. but i need some questions regards getting the data from after login. that means i want the Posting date, Transaction No, account code, debit and credit amount from Journal entries posted in a particular day through MS excel VBA into excel sheets 1 cell A1:E1
how i get it if any possible ways to do that
here my code to login
Public Sub login()
Sheets("Login").Select 'access the login tab
Worksheets("Login").Range("B1").Activate 'put focus on cell B1 (manager)
B1UserID = Trim(ActiveCell.Value2) 'set Businsss One user
ActiveCell.Offset(1, 0).Activate
B1Password = Trim(ActiveCell.Value2) 'set Business One password
ActiveCell.Offset(1, 0).Activate
sqluser = Trim(ActiveCell.Value2) 'set SQL user
ActiveCell.Offset(1, 0).Activate
sqlpass = Trim(ActiveCell.Value2) 'set SQL password
ActiveCell.Offset(1, 0).Activate
Db = Trim(ActiveCell.Value2) 'set Database name
ActiveCell.Offset(1, 0).Activate
Server = Trim(ActiveCell.Value2) 'set Server name
Set company1 = New SAPbobsCOM.Company 'initialate DI company object
company1.DbServerType = dst_MSSQL2005
company1.Server = Server
company1.DbUserName = sqluser
company1.DbPassword = sqlpass
company1.CompanyDB = Db
company1.UserName = B1UserID
company1.Password = B1Password
'connect to the database
lRetCode = company1.Connect
If lRetCode <> 0 Then
sErrMsg = company1.GetLastErrorDescription
MsgBox (sErrMsg)
Else
MsgBox ("Connected to: " & company1.CompanyName)
End If
End Sub
pls help me
advance thanks to solversGordons way is the easiest - just query the OJDT table for journal entry headers and JDT1 for journal entry lines if needed.
But if you want to work with the business objects:
'Journal entry
Dim oJE As SAPbobsCOM.JournalEntries
Set oJE = company1.GetBusinessObject(oJournalEntries)
oJE.GetByKey(1234)
Dim postingDate as String
postingDate = oJE.DueDate
'etc etc -
Hello guys,
I need to send keys to a window in the background, but I don't want it to pop up when I do it as it may cause some errors if I'm typing something at that moment. Is this possible?
The script I'm working on converts a spool to a pdf, but when the save as window comes up, the script stops recording because that is not a SAP screen, but a windows screen.
I was actually able to make it work by ending the script right before executing the transaction, then I used AppActivate and SendKeys to execute the transaction by pressing F8 and saving the file by pressing enter, but I still have these windows popping up while the macro is running, so, is it possible to have the SendKeys point to a specific application without it bringing it to the foreground?
Also, please note that I am new to programming, so I'm not familiar with all the functions.
Thanks in advance.Hello Jahir.
I had several similar request in past.
One requirement was mass convertion of PM orders printout from spool to PDF.
I found a solution where a small ABAP-Report (implemented in coding-area of an SQ02 infoset) Transfer spool data from my SAP user as PDF to a temp Folder on my local HDD.
Then I convert this PDF-files with an small application (pdf2txt.exe) to text-files. Where a small Excel VBA code got an specific text as identifier (PM order number).
So I have pdf-files with spoolnumber-naming and dedicated PM order number. So a small VBA code is renaming my files for better identification by enduser.
Another method was to write an small VBA macro which is able to identify Save-As dialogbox and fillin a specific filename and press 'Save' by using ESER32-API methods and functions.
As you are new with programming I guess both methods are a Little bit to complex for you.
LEt me know when you Need more Information for one of above used methods by me.
MAy you can give some more Details in which Transaction you will Trigger the spools.
Br, Holger -
How to call a labview dll from excel-VBA?
How to call a simple Labview DLL from Excel VBA?
I have seen examples of DLL calls from VB but does it work the same way for VBA? I have 2000 excel and Labview 8.5. I created the DLL and tried to call it from VBA using the same type of code as in NI's website example(ofcourse its a bit diff with 8.5)
http://zone.ni.com/devzone/cda/tut/p/id/...
BUT it errors out when called from excel
ERROR: The object invoked has disconnected from its clientYou would need to provide more details about the LabVIEW DLL, such as the prototypes of the functions (VIs) that you're trying to call, and your actual VBA code. Specifically, what object you're trying to create. You should also make sure the Run-Time Enginer is installed, as well as any required libraries such as the VISA Run-Time if you're using VISA. Have you made sure to enable the ActiveX server for the DLL?
A search yielded the following items that you may wish to peruse:
http://forums.ni.com/ni/board/message?board.id=170&message.id=261345&requireLogin=False
http://forums.ni.com/ni/board/message?board.id=170&message.id=45099&requireLogin=False
http://forums.ni.com/ni/board/message?board.id=170&message.id=299209&requireLogin=False
http://forums.ni.com/ni/board/message?board.id=170&message.id=195846&requireLogin=False -
Using Excel VBA to Print to PDF File?
Hi, All !!
I have an Excel VBA application that creates Excel reports. These need to be sent external to our company in PDF format. I've downloaded the Acrobat SDK and have found the VB sample for AdobePDFSilent. Unfortunately, it appears that this is written for VB or VB.Net as I don't have any of the data types available that are created in the code. However, from another forum, I've gotten some VB code that appears to do many of the processes included in the SDK sample.
The code below doesn't give me any errors, but no PDF file is created.
My VBA code
Declare Function RegOpenKeyA Lib "advapi32.dll" ( _
ByVal Key As Long, _
ByVal SubKey As String, _
NewKey As Long) As Long
Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" ( _
ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, _
lpData As Any, _
ByVal cbData As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" ( _
ByVal hKey As Long) As Long
Sub TestPrintPDF()
Dim strDefaultPrinter As String
Dim strOutFile As String
Dim lngRegResult As Long
Dim lngResult As Long
Dim dhcHKeyCurrentUser As Long
Dim PDFPath As String
Const dhcRegSz As Long = 1
1 Workbooks.Open ("\\master\fnshares\bcbcm\Client Management\Client Services\New Account Fees\09 September 2010\3Q10 Rebate Ltrs\Infi\MacroTest\A02.xls")
2 Select Case ActiveWorkbook.Sheets.Count
3 Case 1
4 Sheets(1).Select
5 Case 2
6 Sheets(Array(Sheets(1).Name, Sheets(2).Name)).Select
7 Case 3
8 Sheets(Array(Sheets(1).Name, Sheets(2).Name, Sheets(3).Name)).Select
9 Case 4
10 Sheets(Array(Sheets(1).Name, Sheets(2).Name, Sheets(3).Name, Sheets(4).Name)).Select
11 Case 5
12 Sheets(Array(Sheets(1).Name, Sheets(2).Name, Sheets(3).Name, Sheets(4).Name, Sheets(5).Name)).Select
13 Case 6
14 Sheets(Array(Sheets(1).Name, Sheets(2).Name, Sheets(3).Name, Sheets(4).Name, Sheets(5).Name, Sheets(6).Name)).Select
15 End Select
16 dhcHKeyCurrentUser = &H80000001
17 strDefaultPrinter = Application.ActivePrinter
18 PDFPath = ActiveWorkbook.Path & Application.PathSeparator 'The directory in which you want to save the file
19 strOutFile = PDFPath & Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) & ".pdf" 'Change the pdf file name if required. This should have the fully qualified path
20 lngRegResult = RegOpenKeyA(dhcHKeyCurrentUser, "Software\Adobe\Acrobat Distiller\PrinterJobControl", lngResult)
21 lngRegResult = RegSetValueEx(lngResult, Application.Path & "\Excel.exe", 0&, dhcRegSz, ByVal strOutFile, Len(strOutFile))
22 lngRegResult = RegCloseKey(lngResult)
23 ThisWorkbook.ActiveSheet.PrintOut copies:=1, ActivePrinter:="Adobe PDF"
24 Application.ActivePrinter = strDefaultPrinter
25 ActiveWorkbook.Close False
End Sub
From what I can determine, the lines 17 & 24 combined basically accomplish the same thing as the SaveandUpdateDefaultPrinter function in the SDK (get and save the current default printer and return it to that default after printing the PDF).
Line 20 opens the Registry key for Distiller\PrinterJobControl which is done in part of the ConvertFile function in the following SDK code.
SDK Code
Dim objDistillerRegKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot
Dim strDistillerSubKey As String = "SOFTWARE\\Adobe\\Acrobat Distiller\\PrinterJobControl"
'Open Current User's Distiller Subkey for writing
objDistillerRegKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(strDistillerSubKey, True)
Line 21 sets the Registry key for Excel with the name of the PDF file to output which also appears to be done in part of the ConvertFile function in the following code.
SDK Code
If (Not objDistillerRegKey Is Nothing) Then 'set reg key value for this app and file
objDistillerRegKey.SetValue(strAppPath, strOutputFile)
objDistillerRegKey.Close()
End If
I have verified, using RegEdit, that this Registry key does get set with the desired output filename.
Line 23 prints the Excel file to PDF when done manually (this was recorded using the Excel Macro Recorder). This should be comparable to the PrintToAdobePDF function in the SDK as below.
SDK Code
Private Sub PrintToAdobePDF(ByVal InputfilePath As String)
'Prints InputFilePath to the AdobePDF printer.
'Since we just gathered all this info programmatically,
'this function assumes the file is present, that it has an
'associated application and that the current user has print privileges.
'Define properties for the print process
Dim pProcInfo As New ProcessStartInfo
pProcInfo.FileName = InputfilePath
pProcInfo.Verb = "Print"
'Make process invisible
pProcInfo.CreateNoWindow = True
pProcInfo.WindowStyle = ProcessWindowStyle.Hidden
'start print process
Dim pMyProc As Process = Process.Start(pProcInfo)
pMyProc.WaitForExit()
End Sub
These are some of the statements I can't do because I don't have a ProcessStartInfo type. What am I doing wrong or NOT doing that the PDF file is not created? I hope I've described my situation in enough, but not too much detail. Thanks for your help.
Nate BreiReinhard & Karl Heinz,
Thank you both for your responses and willingness to work with me on this problem. This is driving me crazy & is getting very frustrating. It seems that I've tried everything that people have suggested (I've also posted on a VB Forum that I subscribe to) and I'm basically doing what works for everyone else but doesn't work for me. I've got to be close.
Reinhard, regarding your last post, it doesn't appear to be a one-time setting. Everytime I come into the Printers Property box (even after I've printed a PDF document manually, that option about system & document fonts is ALWAYS turned on. If it is a registry setting, please let me know how to turn it off. I'm using Adobe Acrobat 9 Standard.
Karl Heinz, I've tried that based on my initial post (see the code there). Since your post, I tried it again. I get the same result, NO FILE is produced anywhere.
I wish I could post pictures, but evidently I can't. So, I going to post first my code (in case you want to try to recreate my problem), then the values of the variables in that code when I run it (so you can I have everything set correctly as far as I know), and finally, the values of the Registry entries that I have after I run it. So, please bear with me as the post may be a little long.
My Code
Declare Function RegOpenKeyA Lib "advapi32.dll" ( _
ByVal Key As Long, _
ByVal SubKey As String, _
NewKey As Long) As Long
Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" ( _
ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, _
lpData As Any, _
ByVal cbData As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" ( _
ByVal hKey As Long) As Long
Sub TestPrintPDF()
Dim strDefaultPrinter As String
Dim strOutFile As String
Dim lngRegResult As Long
Dim lngResult As Long
Dim dhcHKeyCurrentUser As Long
Dim PDFPath As String
Const dhcRegSz As Long = 1
'Workbooks.Open ("\\master\fnshares\bcbcm\Client Management\Client Services\New Account Fees\09 September 2010\3Q10 Rebate Ltrs\Infi\MacroTest\A02.xls")
Workbooks.Open ("H:\A02.xls")
Select Case ActiveWorkbook.Sheets.Count
Case 1
Sheets(1).Select
Case 2
Sheets(Array(Sheets(1).Name, Sheets(2).Name)).Select
Case 3
Sheets(Array(Sheets(1).Name, Sheets(2).Name, Sheets(3).Name)).Select
Case 4
Sheets(Array(Sheets(1).Name, Sheets(2).Name, Sheets(3).Name, _
Sheets(4).Name)).Select
Case 5
Sheets(Array(Sheets(1).Name, Sheets(2).Name, Sheets(3).Name, _
Sheets(4).Name, Sheets(5).Name)).Select
Case 6
Sheets(Array(Sheets(1).Name, Sheets(2).Name, Sheets(3).Name, _
Sheets(4).Name, Sheets(5).Name, Sheets(6).Name)).Select
End Select
dhcHKeyCurrentUser = &H80000001
strDefaultPrinter = Application.ActivePrinter
'The directory in which you want to save the file
PDFPath = ActiveWorkbook.Path & Application.PathSeparator
'Change the pdf file name if required. This should have the fully qualified path
strOutFile = PDFPath & Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) & ".pdf"
lngRegResult = RegOpenKeyA(dhcHKeyCurrentUser, "Software\Adobe\Acrobat Distiller\PrinterJobControl", _
lngResult)
lngRegResult = RegSetValueEx(lngResult, Application.Path & "\Excel.exe", 0&, dhcRegSz, _
ByVal strOutFile, Len(strOutFile))
lngRegResult = RegCloseKey(lngResult)
ThisWorkbook.ActiveSheet.PrintOut copies:=1, ActivePrinter:="Adobe PDF"
'ThisWorkbook.ActiveSheet.PrintOut copies:=1, preview:=False, ActivePrinter:="Adobe PDF", _
printtofile:=True, collate:=True, prtofilename:=strOutFile
'Call printToPdf(strOutFile)
Application.ActivePrinter = strDefaultPrinter
ActiveWorkbook.Close False
End Sub
Sub printToPdf(PDFFilename)
' Define a postscript file name
PSFileName = "H:\TempPostScript.ps"
' Print the Excel range to the postscript file
'Dim MySheet As Worksheet
'Set MySheet = ActiveSheet
ActiveWindow.SelectedSheets.PrintOut copies:=1, preview:=False, ActivePrinter:="Adobe PDF", _
printtofile:=True, collate:=True, prtofilename:=PSFileName
' Convert the postscript file to .pdf
Set myPDF = CreateObject("PdfDistiller.PdfDistiller.1")
myPDF.FileToPDF PSFileName, PDFFilename, ""
End Sub
Values of my Variables When I Run the Code
? dhcHKeyCurrentUser
-2147483647
? strDefaultPrinter
\\tcps01p\FNT12W00 Canon 5020 PCL 5e on Ne04:
? PDFPath
H:\
? strOutFile
H:\A02.pdf
? lngResult
2280
? Application.Path & "\Excel.exe
C:\Program Files\Microsoft Office\OFFICE11\Excel.exe
? dhcRegSz
1
? Len(strOutFile)
10
? PSFileName
H:\TempPostScript.ps
? PDFFilename
H:\A02.pdf
Values of my Registry Entries (HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\PrinterJobControl)
(Default) REG_SZ (value not set)
C:\Program Files\Microsoft Office\OFFICE11\Excel.exe REG_SZ H:\A02.pdf
LastPdfPortFolder - EXCEL.EXE REG_SZ "Q:\Client Management\Client Services\New Account Fees\09 September 2010\3Q10 Rebate Ltrs\Infi\MacroTest
Note: There are a couple of other entries for documents that I've printed manually that I didn't include. Also, the last entry above, contains the value of the folder that I last manually "printed" to.
I've also noticed that I have a Registry SubKey under PrinterJobControl called DownloadFonts. However, the only entry there is:
(Default) REG_SZ (value not set)
Is this the registry key you mentioned, Reinhard?
As you can see in my code, I have 3 different methods that I've tried to print. The first one defaults everything after selecting the Acrobat PDF printer. The second sets the output filename as a PDF (basically what you suggested, Karl Heinz). The third method calls a procedure that prints to a PostScript file & then uses Distiller to print from that file to pdf. This is the method Reinhard suggested.
With the first 2 methods, I get NO error messages, but no file(s) show up. With the 3 method, I get the error about the Fonts checkbox, but it creates a 0K PostScript file. When I skip that statement and run the other 2 statements, I get a log file that says the PostScript file is empty and not PDF file was created.
YIKES... What's going on? Thanks again for attempting to help me!!!
Nate
Maybe you are looking for
-
Launch a splash screen when an iPhone app starts
Hi, I am trying to make a simple game for the iPhone, and when the app launches, I want a splash screen with instructions to come up. I also want the user to be able to push anywhere on the screen to dismiss it. However, the splash screen doesn't loa
-
Video clips in iPhone 4s doesn't play well
Recently the video clips including video camera and any clips in Facebook in my iPhone 4s doesn't play well. Has anyone experienced this before? Any ideas to solve it?
-
Data structure for web-based discussion forum
Hello all. I have begun work on a discussion board forum but have not yet decided upon a data structure for the hierarchy of messages to be left on a board. Any one have any thoughts or experience in this matter? My first thought was to implement a b
-
ClassNotFoundException: oracle.adf.share.http.ServletADFFilter
We have recently started using ADF and I have been tasked with deploying it to a Apache Tomcat environment. I have a simple 'jspx' with a ADF Data Visualization graph on it, that I have deployed to my local tomcat env using the JDeveloper deployment
-
Good afternoon, I have been a BT Customer for over 10 years. I changed address in 2007 and moved my BT account to the new address as appropriate. I recently checked my EQUIFAX credit file and found a default registered at my old address in the summer