Save as to Excel using vba
Post Author: shark70
CA Forum: Desktop Intelligence Reporting
Hi
The vba below saves a file into excel then does some formatting but I need to use the saveas function to set a password for the excel file when opening.
The code in bold is where I am getting stuck
Any ideas on where I'm gioing wrong, I'm fairly new to vba unfortunately
Cheers
Sub SetantaDSAT()
ActiveDocument.RefreshActiveDocument.SaveAs ("K:\CLIENTS (LIVE)\Setanta\08. New Daily Reports\DTT and DSAT Case Type Reports\2008\May 08\") & Format(Date, "ddmmyyyy") & "_" & " TestSetanta DTT Case Type_Subtype Analysis" & ".xls"
Set xlsApp = CreateObject("Excel.Application")xlsApp.Visible = TruexlsApp.Workbooks.Open ("K:\CLIENTS (LIVE)\Setanta\08. New Daily Reports\DTT and DSAT Case Type Reports\2008\May 08\") & Format(Date, "ddmmyyyy") & "_" & " TestSetanta DTT Case Type_Subtype Analysis" & ".xls"
With xlsApp.Worksheets("DSAT Case Type").Activate.ActiveWindow.DisplayGridlines = False.Columns("B:B").EntireColumn.AutoFit.Columns("C:C").EntireColumn.AutoFit.ActiveWindow.Zoom = 75.ActiveWorkbook.SaveAs Filename:="C:\James\Check\Book22.xls", _ FileFormat:=xlNormal, Password:="test", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=FalseEnd With
End Sub
one other thought is that you can create text files with a batch process inside of acrobat. Advanced ---> Document Processing ----> Batch Processing.
Choose new sequence, give it a name
Step 1: Select Commands ----> Choose "execute javascript", then hit "Add." Click on "Execute Javascript" that was just added on the right, then hit the edit button and toss in the script below that I grabbed from the javascript samples (also, if your docs have multiple pages you'll need to embed the for loop into another for loop that cycles through each page). You'd also want to change the name of the saved txt file to the name of pdf you're doing it to. It shouldn't be that hard, but I'm guessing you're probably alot more familiar with VBA then javascript which is why you're choosing to do it from excel. I'm kind of in the same boat of having written a bunch of VBA, but not much javascript. I highly recommend investing some time into learning acrobat scripting b/c VB does have it's limitations when it comes to messing with PDF's.
* function to extract the text content of the current page and save to a file.
try {
var p = this.pageNum;
var n = this.getPageNumWords(p);
app.alert("Number of words in the page: " + n);
var str = "";
for(var i=0;i<n;i++) {
var wd = this.getPageNthWord(p, i, false);
if(wd != "") str = str + wd;
// save the string into a data object
this.createDataObject("whatever.txt",str);
// pop up a file selection box to export the data
this.exportDataObject("whatever.txt");
// clean up
this.removeDataObject("whatever.txt");
} catch (e) {
app.alert(e)
Similar Messages
-
Export Project Tasks to Excel using VBA by Custom Field
Question referring to the link:
http://social.technet.microsoft.com/Forums/projectserver/en-US/9c46458c-893f-41ba-bd46-bdb59c533f4a/export-project-tasks-to-excel-using-vba-by-custom-field?forum=project2010custprog
Help needed. I have inserted my question at this address for Andrew or anybody else to reply. Hope to hear from you.
Regards,
ChuckThank you Andrew for getting back to me and I have found somewhere on the net the following macro that would do the job for the version 2007. Here is a copy for those that may need it.
Option Explicit
Sub CreateMenus()
Dim cbrMain As CommandBar
Dim ctlMain As CommandBarControl
Dim ctlOLExport1 As CommandBarControl
Dim ctlOLExport2 As CommandBarControl
Dim ctlOLExport3 As CommandBarControl
Set cbrMain = Application.CommandBars.ActiveMenuBar
Set ctlMain = cbrMain.Controls.Add(Type:=msoControlPopup, Temporary:=True)
ctlMain.Caption = "Export to Outlook"
Set ctlOLExport1 = ctlMain.CommandBar.Controls.Add(Type:=msoControlButton)
With ctlOLExport1
.Caption = "Selection to Outlook tasks"
.OnAction = "Macro """ & "Export_Selection_To_OL_Tasks"""
End With
Set ctlOLExport2 = ctlMain.CommandBar.Controls.Add(Type:=msoControlButton)
With ctlOLExport2
.Caption = "Selection to Outlook appointments"
.OnAction = "Macro """ & "Export_Selection_To_OL_Appointments"""
End With
Set ctlOLExport3 = ctlMain.CommandBar.Controls.Add(Type:=msoControlButton)
With ctlOLExport3
.Caption = "Selection to Outlook notes"
.OnAction = "Macro """ & "Export_Selection_To_OL_Notes"""
End With
End Sub
Cheers!
Chuck -
I would like to execute an existing BW report from Excel (using VBA).
I would like to execute an existing BW report from Excel (using VBA) and download the results into Excel. I understand that there is an Excel Add-In which (I believe) should allow me to do this. I am an experienced user of Excel / VBA but I have virtually no experience with SAP. If someone could point me to any source of information or specific instructions I would be extremely appreciative. I've done multiple searches on the internet but everything I find seems to assume more knowledge of SAP and SAP acronyms than I possess.
Paul,
If your company (or your client's company) has an SAP license (I assume this is the case, since there would be no other reason for you to want to access an SAP system using Excel), there is a person in your company who can request an ID for you. It is called a SAP Service Marketplace userid, more commonly called an 'S' number. This person in your company is usually a Basis Administrator. Go to your SAP Basis team and ask them for access to Service Marketplace.
The common solution for your Excel analysis problem is to install the Bex Analyzer on your PC. You will need these same guys (Basis Team) to help you with getting the required SAP access, and to install the associated SAP software onto your PC.
In the meantime, here is some bedtime reading for you.
Analysis &amp; Reporting: BEx Analyzer - Business Intelligence - SAP Library
Best Regards,
DB49 -
Is there a way to Update and SaveAs, an XFA form using VBA or similar ?
All:
Need help to auto-fill and auto-save PDFs using VBA or some other means.
I have created an XFA form using LiveCycle ES ( v8 ) with a few fields.
What I need to do is repeat these steps below for 200+ PDF forms
Open the blank PDF form
Update 3 fields
Save the PDF with a new name
My Excel VBA code so far ( ** Copied from another post ) where dFile = "C:\temp.pdf" and dAccount = "Any Account"
Sub rxOpenPDF_UpdateFields(dFile, dAccount )
Dim pdfApp As Acrobat.AcroApp, pdfPDDoc As Acrobat.AcroPDDoc, jso As Object
Dim str1$, bolOpen As Boolean, strFile$
Set pdfApp = CreateObject("AcroExch.App")
Set pdfPDDoc = CreateObject("AcroExch.PDDoc")
bolOpen = pdfPDDoc.Open(dFile)
Set jso = pdfPDDoc.GetJSObject
str1 = jso.getfield("Account_Name").Value ' Will appreciate if there is a way to set a field value
pdfApp.Exit
Set pdfApp = Nothing
Set pdfPDDoc = nothing
Set jso = Nothing
End Sub
Excel VBA is shutting down ( cannot recover ) when it runs the pdfPDDoc.Open statement
Any help will be very appreciated
Aubrey
I am on Windows XP,
In VBA, I have created Tool References to [Adobe Acrobat 9.0 Type Library]
Downloaded the Acrobat v9 SDK but am lost trying to locate any help for simple VBA.lrosenth,
Would I be able to Update & SaveAs with a newer version of LiveCycle ( does Adobe still have a LiveCycle line ) ?
I was looking at InDesign but am not sure if it has the functionality that I need ( i.e. create multiple forms from an Excel list)
.. also am unsure of the learning curve.
Aubrey -
How can I export multiple PDF fillable forms into a spreadsheet (Excel) using VBA?
Hi guys,
I never used VBA with with Adobe Acrobat. I would like a tip to start doing that. What I would like to do know is:
1 - I have multiple PDF Forms that are filled.
2 - I want all the data from those forms to be exported to Excel via VBA code.
3 - Adobe Acrobat already have an option to do that manually (Forms > Merge Data Files Into Spreadsheet) and it works perfectly.
4 - I would like to access that feature using VBA, then generate a spreadsheet.
Any tips? How can I start?
Thanks!A good place to start is Karl Heinz Kremer's blog, where he has a few examples:
http://khkonsulting.com/2010/09/reading-pdf-form-fields-with-vba/ -
Manipulating ShockwaveFlash in Excel Using VBA
I am trying to change various variables in an embedded shockwaveplayer but I cannot get the video to play through code. My code is below. Any help would be appreciated and thanks in advance.
Sub TestVideo()
On Error GoTo iErrors
Set appxl = Excel.Application
Set sht = appxl.ActiveSheet
Dim shFl As ShockwaveFlash
For Each obj In sht.OLEObjects
If InStr(obj.progID, "ShockwaveFlash") > 0 Then
Set shFl = obj.Object
shFl.LoadMovie 0, shFl.Movie 'http://www.youtube.com/watch?v=1YuH8IoqaAg&feature=feedrec_grec_index
Exit For
End If
Next
Exit Sub
iErrors:
Err.Clear
Resume Next
End Sub
Thanks againHi Mr.Thomas,
Based on my understanding, the suggestion using Regular Expressions is a very helpful. Have you fixed the issue now?
If you still have the issue about develop with Regular Expressions using VBA, I suggest that you reopen a new thread in
Visual Basic for Application forum.
Regards & Fei
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. -
BAPI Access from Excel using VBA
Im writing an excel macro (VBA) to call a bapi that populates a spreadsheet.
The user will then do some manipulation of the data collected, and then it must be sent back to sap.
The Bapi in question is BAPI_GET_USER_DETAIL
*" IMPORTING
*" VALUE(USERNAME) LIKE BAPIBNAME-BAPIBNAME
*" EXPORTING
*" VALUE(LOGONDATA) LIKE BAPILOGOND STRUCTURE BAPILOGOND
*" VALUE(DEFAULTS) LIKE BAPIDEFAUL STRUCTURE BAPIDEFAUL
*" VALUE(ADDRESS) LIKE BAPIADDR3 STRUCTURE BAPIADDR3
*" VALUE(COMPANY) LIKE BAPIUSCOMP STRUCTURE BAPIUSCOMP
*" VALUE(SNC) LIKE BAPISNCU STRUCTURE BAPISNCU
*" VALUE(REF_USER) LIKE BAPIREFUS STRUCTURE BAPIREFUS
*" VALUE(ALIAS) LIKE BAPIALIAS STRUCTURE BAPIALIAS
*" TABLES
*" PARAMETER STRUCTURE BAPIPARAM OPTIONAL
*" PROFILES STRUCTURE BAPIPROF OPTIONAL
*" ACTIVITYGROUPS STRUCTURE BAPIAGR OPTIONAL
*" RETURN STRUCTURE BAPIRET2
*" ADDTEL STRUCTURE BAPIADTEL OPTIONAL
*" ADDFAX STRUCTURE BAPIADFAX OPTIONAL
*" ADDTTX STRUCTURE BAPIADTTX OPTIONAL
*" ADDTLX STRUCTURE BAPIADTLX OPTIONAL
*" ADDSMTP STRUCTURE BAPIADSMTP OPTIONAL
*" ADDRML STRUCTURE BAPIADRML OPTIONAL
*" ADDX400 STRUCTURE BAPIADX400 OPTIONAL
*" ADDRFC STRUCTURE BAPIADRFC OPTIONAL
*" ADDPRT STRUCTURE BAPIADPRT OPTIONAL
*" ADDSSF STRUCTURE BAPIADSSF OPTIONAL
*" ADDURI STRUCTURE BAPIADURI OPTIONAL
*" ADDPAG STRUCTURE BAPIADPAG OPTIONAL
*" ADDCOMREM STRUCTURE BAPICOMREM OPTIONAL
*" GROUPS STRUCTURE BAPIGROUPS OPTIONAL
Ive Managed to glean from various sources on the internet, the various basics on doing a bapi call from VBA
Here is what i have so far.
Private Sub Fetch_User_details_Click()
'Take username in cell 2,2 and check to see it it exists.
'Display the First and Last name of the user
'Get list of all roles and their expiry dates and populate list
Dim R3, MyFunc, App As Object
Dim SEL_TAB, NAMETAB, TABENTRY, ROW As Object
Dim Result As Boolean
Dim iRow, iColumn, iStart, iStartRow As Integer
'RFC Paramaters
Dim Pusername As Variant
Dim Preturn As Variant
Dim copyFromc As String
'Clear Table Section of Spreadsheet
Worksheets("Sheet1").Select
For x = 9 To 200
For y = 1 To 8
Worksheets("Sheet1").Cells(x, y).ClearContents
Next y
Next x
'Create Server object and Setup the connection
Set R3 = CreateObject("SAP.Functions")
R3.Connection.System = ""
R3.Connection.client = ""
R3.Connection.user = ""
R3.Connection.Password = ""
R3.Connection.Language = "EN"
'Logon to SAP
If R3.Connection.logon(0, False) <> True Then
Exit Sub
End If
'R3.loglevel = 9
'R3.logfilename = "c:guilog.txt"
Set MyFunc = R3.Add("BAPI_USER_GET_DETAIL")
copyFromc = Worksheets("Sheet1").Cells(3, 2).Text
Set Pusername = MyFunc.exports("USERNAME")
Pusername.Value = copyFromc
'Call the BAPI
If MyFunc.call Then
' ok now what ?
' Process the returned data into the spreadsheet
Else
MsgBox ("Call returned FALSE")
End If
'Close Connection to SAP
R3.Connection.logoff
End Sub
To update the data ( User Role Assignements ) i will be using bapi BAPI_USER_ACTGROUPS_ASSIGN
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(USERNAME) LIKE BAPIBNAME-BAPIBNAME
*" TABLES
*" ACTIVITYGROUPS STRUCTURE BAPIAGR
*" RETURN STRUCTURE BAPIRET2
* Dieser Baustein ist gleichgestellt mit der Pflege eines Benutzers
* über die Pflegetransaktion, gepflegt werden die Felder, für die die
* Pflege erlaubt ist
I need help deciphering the data received from the bapi and then repackaging it using VBA.
I know writing this in ABAP would take less than 30 mins, but that is not an option for me.Ok, Ive made some headway
I can now Read all the data i need from SAP
Now comes the bit to write it back again. Will Update when i have a solution
Private Sub copydata_Click()
Dim x1 As Integer, x2 As Integer
'copy all data from "Copy From" to "Copy To"
'first determine how many rows contain roles
'before copying the roles, check that the destination user has no roles assigned
If Cells(9, 6).Text <> "" Then
MsgBox ("Error. Destination User already has Roles assigned.")
Exit Sub
End If
For x1 = 0 To 1000
If Cells(9 + x1, 1).Text = "" Then
Exit For
End If
Next
Worksheets("Sheet1").Range(Cells(9, 1), Cells(9 + x1 - 1, 4)).Copy _
Destination:=Worksheets("Sheet1").Range(Cells(9, 6), Cells(9 + x1, 9))
For x2 = 1 To x1
Worksheets("Sheet1").Cells(9 + x2 - 1, 8).Value = Date
Next
End Sub
Sub Mail_small_Text_Outlook()
' Is working in Office 2000-2007
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
strbody = "User " & Worksheets("Sheet1").Cells(3, 7).Text & _
" Has Been Moddelled off of User " & _
Worksheets("Sheet1").Cells(3, 2).Text & " in system " & _
Worksheets("Connection").Cells(1, 2).Text & vbNewLine & vbNewLine & _
"Please Adjust Mitigating Controls Accordingly"
On Error Resume Next
With OutMail
.To = Worksheets("Connection").Cells(10, 2).Text
.CC = ""
.BCC = ""
.Subject = "User Modelled"
.Body = strbody
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Private Sub Fetch_CopyTo_User_Click()
'Take username in cell 3,7 and check to see it it exists.
'Display the First and Last name of the user
'Get list of all roles and their expiry dates and populate list
Dim R3, MyFunc, App As Object
Dim SEL_TAB, NAMETAB, TABENTRY, ROW As Object
Dim Result As Boolean
Dim iRow, iColumn, iStart, iStartRow As Integer
'RFC Paramaters
Dim Pusername As Object
Dim PAddress As Object
Dim PTable As Object
Dim Preturn As Object
Dim copyFromc As String
'Clear Table Section of Spreadsheet
Worksheets("Sheet1").Cells(5, 8).ClearContents
Worksheets("Sheet1").Cells(6, 8).ClearContents
'Create Server object and Setup the connection
Set R3 = CreateObject("SAP.Functions")
R3.Connection.System = Worksheets("Connection").Cells(1, 2).Text
R3.Connection.SystemNumber = Worksheets("Connection").Cells(2, 2).Text
R3.Connection.Destination = Worksheets("Connection").Cells(3, 2).Text
R3.Connection.HostName = Worksheets("Connection").Cells(4, 2).Text
R3.Connection.client = Worksheets("Connection").Cells(5, 2).Text
R3.Connection.user = Worksheets("Connection").Cells(6, 2).Text
R3.Connection.Password = Worksheets("Connection").Cells(7, 2).Text
R3.Connection.Language = Worksheets("Connection").Cells(8, 2).Text
'Logon to SAP
If R3.Connection.Logon(0, -1) <> True Then
MsgBox ("We Had a Logon Error")
Exit Sub
End If
'R3.loglevel = 9
'R3.logfilename = "c:\guilog.txt"
Set MyFunc = R3.Add("BAPI_USER_GET_DETAIL")
Set Pusername = MyFunc.exports("USERNAME")
Set PAddress = MyFunc.imports("ADDRESS")
Set Preturn = MyFunc.tables("RETURN")
Set PTable = MyFunc.tables("ACTIVITYGROUPS")
Pusername.Value = Worksheets("Sheet1").Cells(3, 7).Text
'Call the BAPI
If MyFunc.call Then
Dim xxx As String
Worksheets("Sheet1").Cells(5, 7).Value = PAddress.Value("FIRSTNAME")
Worksheets("Sheet1").Cells(6, 7).Value = PAddress.Value("LASTNAME")
'Get Assigned Roles
Dim datarec As Object
Dim datafld As Object
x = 9
For Each datarec In PTable.Rows
Worksheets("Sheet1").Cells(x, 6).Value = datarec("AGR_NAME")
Worksheets("Sheet1").Cells(x, 7).Value = datarec("AGR_TEXT")
Worksheets("Sheet1").Cells(x, 8).Value = datarec("FROM_DAT")
Worksheets("Sheet1").Cells(x, 9).Value = datarec("TO_DAT")
x = x + 1
Next
copydata.Enabled = True
Else
MsgBox ("Error Calling Function - Probably Authorizations")
End If
'Close Connection to SAP
R3.Connection.logoff
End Sub
Private Sub Fetch_User_details_Click()
'Take username in cell 3,2 and check to see it it exists.
'Display the First and Last name of the user
'Get list of all roles and their expiry dates and populate list
Dim R3, MyFunc, App As Object
Dim SEL_TAB, NAMETAB, TABENTRY, ROW As Object
Dim Result As Boolean
Dim iRow, iColumn, iStart, iStartRow As Integer
'RFC Paramaters
Dim Pusername As Object
Dim PAddress As Object
Dim PTable As Object
Dim Preturn As Object
Dim copyFromc As String
'Clear Table Section and other areas of Spreadsheet
Worksheets("Sheet1").Select
For x = 9 To 1000
For y = 1 To 9
Worksheets("Sheet1").Cells(x, y).ClearContents
Next y
Next x
Worksheets("Sheet1").Cells(5, 2).ClearContents
Worksheets("Sheet1").Cells(6, 2).ClearContents
Worksheets("Sheet1").Cells(5, 7).ClearContents
Worksheets("Sheet1").Cells(6, 7).ClearContents
copydata.Enabled = False
'Create Server object and Setup the connection
Set R3 = CreateObject("SAP.Functions")
R3.Connection.System = Worksheets("Connection").Cells(1, 2).Text
R3.Connection.SystemNumber = Worksheets("Connection").Cells(2, 2).Text
R3.Connection.Destination = Worksheets("Connection").Cells(3, 2).Text
R3.Connection.HostName = Worksheets("Connection").Cells(4, 2).Text
R3.Connection.client = Worksheets("Connection").Cells(5, 2).Text
R3.Connection.user = Worksheets("Connection").Cells(6, 2).Text
R3.Connection.Password = Worksheets("Connection").Cells(7, 2).Text
R3.Connection.Language = Worksheets("Connection").Cells(8, 2).Text
'Logon to SAP
If R3.Connection.Logon(0, -1) <> True Then
MsgBox ("We Had a Logon Error")
Exit Sub
End If
'R3.loglevel = 9
'R3.logfilename = "c:\guilog.txt"
Set MyFunc = R3.Add("BAPI_USER_GET_DETAIL")
Set Pusername = MyFunc.exports("USERNAME")
Set PAddress = MyFunc.imports("ADDRESS")
Set Preturn = MyFunc.tables("RETURN")
Set PTable = MyFunc.tables("ACTIVITYGROUPS")
Pusername.Value = Worksheets("Sheet1").Cells(3, 2).Text
'Call the BAPI
If MyFunc.call Then
Dim xxx As String
Worksheets("Sheet1").Cells(5, 2).Value = PAddress.Value("FIRSTNAME")
Worksheets("Sheet1").Cells(6, 2).Value = PAddress.Value("LASTNAME")
'Get Assigned Roles
Dim datarec As Object
Dim datafld As Object
x = 9
For Each datarec In PTable.Rows
Worksheets("Sheet1").Cells(x, 1).Value = datarec("AGR_NAME")
Worksheets("Sheet1").Cells(x, 2).Value = datarec("AGR_TEXT")
Worksheets("Sheet1").Cells(x, 3).Value = datarec("FROM_DAT")
Worksheets("Sheet1").Cells(x, 4).Value = datarec("TO_DAT")
x = x + 1
Next
Else
MsgBox ("Error Calling Function - Probably Authorizations")
End If
'Close Connection to SAP
R3.Connection.logoff
End Sub
Private Sub UpdateSap_Click()
End Sub -
I am trying to do an RFC call from Excel to SAP using VBA. RFC is working fine for most the RFC enabled Function Modules except DDIF_FIELDINFO_GET and DDIF_FIELDLABEL_GET.
What can be the reason for this?
Can someonme please help me with a macro code where these FMs are working.
Also can someone please help me with some tutorial on SAP connection with Excel.
<REMOVED BY MODERATOR - REQUEST OR OFFER POINTS ARE FORBIDDEN>
Edited by: Alvaro Tejada Galindo on Nov 12, 2008 9:14 AMHello Jon.
DDIF_FIELDINFO_GET is not working for me either. But I have used another FM (/ZOPTION/LIVE_DDIF_FIELDINFO):
Public Sub RFC_FIELDINFO()
Dim Func As Object
Dim sapConn As Object
Dim tblFIELDTAB
Dim tblFIXED_VALUES
Dim intRow%
Dim intCol%
'* Sub : Call FM /ZOPTION/LIVE_DDIF_FIELDINFO *
'* Author : Holger Köhn *
'* Created : 23.08.2014 *
'* Changed : *
ThisWorkbook.Sheets("TEST").Activate
Cells.Select
Selection.ClearContents
ThisWorkbook.Sheets("TEST").Range("A1").Select
'* create RFC-Connection *
Set sapConn = CreateObject("SAP.Functions")
sapConn.Connection.RfcWithDialog = True
If sapConn.Connection.LogOn(1, False) <> True Then
MsgBox "Cannot Logon to SAP"
Exit Sub
End If
DoEvents
'* run FM /ZOPTION/LIVE_DDIF_FIELDINFO *
Set Func = sapConn.Add("/ZOPTION/LIVE_DDIF_FIELDINFO")
Func.Exports("TABNAME") = "AUFK"
Set tblFIELDTAB = Func.Tables("FIELDTAB")
If Func.Call = False Then
MsgBox Func.Exception
Exit Sub
Else
Application.ScreenUpdating = False
For intCol = 1 To tblFIELDTAB.ColumnCount
ThisWorkbook.Sheets("TEST").Cells(1, intCol).Value = tblFIELDTAB.ColumnName(intCol)
Next
If tblFIELDTAB.RowCount > 0 Then
For intRow = 1 To tblFIELDTAB.RowCount
For intCol = 1 To tblFIELDTAB.ColumnCount
ThisWorkbook.Sheets("TEST").Cells((intRow + 1), intCol).Value = tblFIELDTAB(intRow, intCol)
Next
Next
ThisWorkbook.Sheets("TEST").Activate
End If
Columns.AutoFit
Application.ScreenUpdating = True
End If
'* clear tblFIELDTAB *
Do Until tblFIELDTAB.RowCount = 0
Call tblFIELDTAB.Rows.Remove(1)
Loop
Set sapConn = Nothing
Set Func = Nothing
Set tblFIELDTAB = Nothing
End Sub -
Open Multiple PDFs from within excel using VBA
Hi,
I'm using excel 2010 and would like to open pdfs based on filenames I have listed in excel.
I attached a little of my code below which gives an idea of what I'm doing.
First question:
Is there a way to open mutiple files so that they are in one "instance" of adobe?
The way this currently works, is it opens up a whole new window for each file which can make desktop very cluttered.
Second question:
Our pdfs are actually in Sharepoint and so what I am first doing, is converting the URL to point to a mapped directory of the Sharepoint Site.
For this to work, the user must first map the sharepoint directory to a specific drive letter.
I'm wondering if there's a way to pass an actual URL via a shell command so I can skip the mapped drive bit? When I try it, it doesn't open the file.
Thanks!
My current vba:
'sFileName = full URL of the file in sharepoint
'Replace URL with Mapped Directory
sFileName = Replace(sFileName, "http://aamteams.alv.autoliv.int/sites/alvgmbu/", "A:\")
'Replace slashes in URL
sFileName = Replace(sFileName, "/", "\")
'Test if file exists before opening so adobe doesn't hang up on opening
If Dir(sFileName) = "" Then
A81_Try_Opening_In_Adobe = False
Exit Function
End If
l_strProg = GetDefaultProgram(sFileName)
'Execute function to open PDF
Shell l_strProg & " " & sFileName, vbNormalFocusHi Test,
We would like to open directly in adobe for the following reasons:
1. The users like opening our pdfs in adobe over browsers by a large margin.
2. If we use a mapped drive and adobe, you can see the filenames in the start bar which is important when you have multiple files.
If you open in browser (like we do today), you only see the left side of URL
Left side of URL is always the same so it does no good to see what file your in.
3. We have had issues where sometimes the pdfs open "blank" until I refresh the browser.
4. We are also looking for a way to make a local cache of most common files for faster loads.
But maybe I will give shell execute a try if it can find a local copy first in the code.
Then open in browser as last resort.
Using either shell or shell execute, is it possible to open multiple adobe files in the same instance or will we always have to get one instance for every pdf?
Thanks for the help! -
How to save then quit excel using activeX
The task that I need to do is open existing excel file, append data to the last row, save data then close it. Everything works fine except saving the data. I used property workbook note to save then invoke node to close a workbook then invoke node to quit excel application. I watched and see that the data is written to the sheet but when I closed it, it is not saved.
System: Window NT and Excel2000
Thank youmai wrote:
>
> The task that I need to do is open existing excel file, append data to
> the last row, save data then close it. Everything works fine except
> saving the data. I used property workbook note to save then invoke
> node to close a workbook then invoke node to quit excel application.
> I watched and see that the data is written to the sheet but when I
> closed it, it is not saved.
>
> System: Window NT and Excel2000
Use Task Manager to check if Excel is still running.
I find that the programmatic close of Excel doesn't work. Excel is left
running until you actually quit either LabVIEW or the built app!
Side-effect: if you then launch Excel to view a document, the screen
isn't redrawn right.
Mark -
Save data to excel using froms_ole builtin
Hi All,
can somebody send me an example how to save any data to excel workbook
using FORMS_OLE builtin package (or OLE2 in later versions) ?
I'm working with forms 4.5
Thanks
BranoFor merging of cells you can refer following code!
[Merging of cells.|https://www.sdn.sap.com/irj/scn/wiki?path=/display/community/oleconceptfordownloadingthereportoutputintoexcel]
Regards,
Lalit Mohan Gupta. -
I am looking to save a pdf file as plain text through VBA, however I am getting the error "Security Settings Prevent access to this property or method". I am using Acrobat 9.0 Standard. Please help!
Here is the code I am using in VBA:
Dim AcroXApp As Object
Dim AcroXAVDoc As Object
Dim AcroXPDDoc As Object
Set AcroXApp = CreateObject("AcroExch.App")
AcroXApp.Hide
Set AcroXAVDoc = CreateObject("AcroExch.AVDoc")
AcroXAVDoc.Open strPDFPath, "Acrobat"
AcroXAVDoc.BringToFront
Set AcroXPDDoc = AcroXAVDoc.GetPDDoc
Dim jsObj As Object
Set jsObj = AcroXPDDoc.GetJSObject
jsObj.SaveAs strOutputFile, "com.adobe.acrobat.plain-text"
AcroXAVDoc.Close False
AcroXApp.ExitYou can try it with iText dll
It is open source!
This is in C# but in VB is the "same":
public string GetPdf(string _path) {
var sb = new StringBuilder();
var path = _path;
try
PdfReader reader = new PdfReader(path);
int n_pages = reader.NumberOfPages;
int i = 0;
for (i = 1; i <= 1; i++)
var pageBytes = reader.GetPageContent(i);
if (pageBytes != null)
var token = new PRTokeniser(pageBytes);
while (token.NextToken())
var tknType = token.TokenType;
var tknValue = token.StringValue;
if (tknType == PRTokeniser.TokType.STRING)
sb.Append(token.StringValue);
catch (Exception e)
return e.Message;
return sb.ToString();
Cheers =) -
Importing Structure field values in Excel using VBA and SAP RFC
I am calling a RFC MEASUREM_DOCUM_RFC_SINGLE_001 from Excel VBA. The export parameters of the RFC has a parameter MEASUREMENT_DOCUMENT and structure COMPLETE_DOCUMENT. I am able to get back parameter value in excel from RFC using
ActiveCell = Funct.imports("MEASUREMENT_DOCUMENT")
Now I want to get the value of one of the fields say POINT of the structure COMPLETE_DOCUMENT in Excel. The following code doesnt work
ActiveCell = Funct.imports("COMPLETE_DOCUMENT-POINT")
It gives an error.
Even I have tried to using code for tables
dim tab as object
set tab = funct.tabels("COMPLETE_DOCUMENT")
but it did'nt work.
Can any one help me how to access the field value of a structure?
regards
RavindraI am calling a RFC MEASUREM_DOCUM_RFC_SINGLE_001 from Excel VBA. The export parameters of the RFC has a parameter MEASUREMENT_DOCUMENT and structure COMPLETE_DOCUMENT. I am able to get back parameter value in excel from RFC using
ActiveCell = Funct.imports("MEASUREMENT_DOCUMENT")
Now I want to get the value of one of the fields say POINT of the structure COMPLETE_DOCUMENT in Excel. The following code doesnt work
ActiveCell = Funct.imports("COMPLETE_DOCUMENT-POINT")
It gives an error.
Even I have tried to using code for tables
dim tab as object
set tab = funct.tabels("COMPLETE_DOCUMENT")
but it did'nt work.
Can any one help me how to access the field value of a structure?
regards
Ravindra -
Smart View Ribbon not shown when Excel is invoked using VBA
Dear Hyperion Gurus,
I am in need to invoke smartview refresh by calling excel using VBA from an excel module in another sheet(master template). But when I invloke Excel using VBA, smartview ribbon does not get activated, due to which the HypConnect, HypVMenuRefresh command does not work. If I directly open excel and run the module it connects fine and does the refresh without any problem. I have tried to enable and disable smartview using VBA but it does not work either. If I call excel directly using a batch using Call command, then it works fine, however the batch file does not close as if I use ThisWorkbook.Close command, then it does not completely close Excel, the instance still runs, and if I try to close using Application.Quit, then it closes down Excel completely. Any help would be highly appreciated.
Thanks and Regards,
SiddN.Hi,
I was able to achieve this using batch files by calling the excel templates one by one.
Thanks,
SiddN. -
I've got some tables in Access which I export to Excel using VBA. Once exported, I'd like to add some pivot tables, special formatting and formulas into the workbook. Any idea how to do this? Here are some specific tasks after the export:
1. Insert a pivot table into a 2nd sheet. The pivot table will have a filter field.
2. Format the column widths in that pivot table and add some conditional cell colors
Anybody know how to code this? I assume I'll need to export from access then open the excel file and use excel object model from within access?
ajwYou can certainly import Access tables into Excel:
http://www.erlandsendata.no/english/index.php?d=envbadacimportado
http://www.erlandsendata.no/english/index.php?d=envbadacimportdao
http://www.erlandsendata.no/english/index.php?d=envbadacrs2ws
See this too.
http://www.accessmvp.com/KDSnell/EXCEL_Export.htm#WriteRstFile
http://www.accessmvp.com/KDSnell/EXCEL_Export.htm#ExpCopyFromRst
That's just several similar, but slightly different, ways to do the same thing. Once your data is in Excel, turn on the Macro Recorder and run through the steps you need to do, to get the Pivot Table the way you want it, then turn off the Macro Recorder
and view the code.
You will almost certainly need to make some modifications to the recorded code, because everything will be fixed (hard-coded). Post back with additional questions, or start a new thread, to see how to make the next part(s) work. Just get comfortable
with the first part(s) for now.
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.
Maybe you are looking for
-
Firefox 11.0 was working on this computer (windows 7 64 bit) but went into window xp mode.
-
Switching from PC to MAC -Will I have a problem with Lightroom?
I am getting ready to switch from a PC to a MAC ( I think). I know I will need new Lightroom software. Other than that, will I have any problems. Will it read my files automatically? Sepcifically, will it maintain my key words, ratings, metadata,
-
Running Business Rules on Composite Forms
Hi, I'm using Planning v11.1.2, and I am trying to get a business rule to run from a Composite web form. The version and entity are the only prompts in the business rule, and they are shared globally on the component forms. If I put the business rule
-
Weblogic security & EJB role based access
How does (or not) weblogic security tie into the EJB notion of role based control ? Can we create a 'custom' security mechanism for EJB (which basically uses the EJB facilities but extends it within the application) by using custom weblogic realms ?
-
I have lost my Archive button on my blog, how can I find it again?