Creating bookmark using VBA

Hi all,
Im creating a pdf file with a number of bookmarks in it from Access using VBA. I want each bookmark to refer to a page in the document. Just wanted to confirm that I have understood this correcly. With current functionality I must use javascript to do this i.e this.pageNum=2 when I create the bookmark(createChild under JSObject). There is no possiblity to create it using the "standard" go to page functionality? I want to avoid javascript as much as possible since this functionality can be disabled. Any ideas would be greatly appreciated.
Best Regards,
Ingman

I believe so. Or of course someone may already have commercially developed one and is selling it.
Unless you can do something like get from Access to Word, automate adding Word styles, then use PDFMaker to make a PDF with bookmarks from styles.

Similar Messages

  • How Create bookmark

    Hi
    can any one tell me how create bookmark using java script ?
    I want to create a bookmark on a Billjoy, there is a problem in parameter of  bookmarks.Add() function.
    INDESIGN::_Application oApplication;
    INDESIGN::Document objDoc;
    objDoc=oApplication.GetActiveDocument();
    INDESIGN::Pages pages= objDoc.GetPages();
    INDESIGN::Page  page =pages.GetItem(COleVariant((long)1));
    INDESIGN::TextFrames TextFrames =page.GetTextFrames();
    INDESIGN::TextFrame TextFrame = TextFrames.Add(covOptional,(long)1433299822,covOptional);
    TextFrame.SetContents(COleVariant(L"Billjoy"));
    // i want to create bookmark on billjoy
    INDESIGN::Bookmarks bookmarks = objDoc.GetBookmarks();
    bookmarks.Add(
    Parameters is destination of type  HyperlinkExternalPageDestination or HyperlinklPageDestination or
    HyperlinklTextDestination or Page.
    How use these type of parameter.
    Thanks.

    After creating a new folder ("plus" sign, or "Bookmarks" menu, then "Add Bookmark folder" or "shift-apple-N"), click on the parent folder (the one you want the new folder to go in as a subfolder). Then drag the new folder over to the right, where the bookmarks are listed.
    As an alternative, if you click on the parent folder on the left that you want a new folder to go in, then click into the area on the right (that lists the bookmarks in a folder), you can then "Add Bookmark folder" (again, "shift-apple-N") or use the "plus" sign on the bottom under the bookmarks.

  • How to create bookmarks by using J2ME

    Hi! Does anyone knows how to create bookmarks by using J2ME?

    hey , did u get any help on this?
    --vijay
    Hi! Does anyone knows how to create bookmarks by
    using J2ME?

  • Creating Bookmarks in form using JavaScript on searched string.

    Hi all,
    I am currently working on SAP Adobe Form to which I need to add bookmarks
    dynamically where the Searched string is found and this should be done during
    its Assembly. Any help is appreciated.
    Edited by: gopbhav on Jul 19, 2010 8:12 PM
    Edited by: gopbhav on Jul 19, 2010 8:28 PM

    Otto,
    We have forms created with bindings as well as document (word document) are being (merged)/populated dynamically.
    After it has been compiled I need to do a search for "string" and where the first "string" is matched I need to add a bookmark to that particular page. Bookmarks are used widely in Acrobat and there is a JavaScript to create bookmark available but the code for Adobe LC/ SAP Adobe Form is different. So I need help if someone knows how I go about do this.
    gopbhav

  • How do I automatically create bookmarks in adobe using the Scanjet pro 3000 s2?

    How do I automatically create bookmarks in adobe using the Scanjet pro 3000 s2?

    Does the file you are writing have a timestamp in it?  If so you could read the timestamp from the last time it was written and see if the day has changed, handling the name of the file appropriately.  The easiest way to record the timestamp is probably to write the timestamp as the number of seconds that have elapsed since 12:00 am on Firday January 1st 1904 in UT.  The "Get Date/Time in Seconds" function will give you this value.
    Message Edited by jmcbee on 03-05-2009 12:56 PM
    CLA, CLED, CTD,CPI, LabVIEW Champion
    Platinum Alliance Partner
    Senior Engineer
    Using LV 2013, 2012
    Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.

  • Can I create bookmarks on PDF document using stadard acrobat writer? or only using professional acrobat writer?

    can I create bookmarks on PDF document using stadard acrobat writer? or only using professional acrobat writer?

    Hi hagitl14083762,
    Bookmarking in available in both Acrobat Pro and Standard. You'll find instructions here: Adobe Acrobat X Standard * Create a bookmark (while written for Acrobat X, these instructions apply to Acrobat XI as well).
    Please let us know if you have additional questions.
    Best,
    Sara

  • Is there a way to create a PDF package using VBA?

    Hello everyone,
    I'm working on a project that ends with a series of PDFs.  For sending ease, I'd like to compile all of these into a single package.  Is there any way this can be done using VBA?
    Any help is appreciated.
    Thanks in advance!

    At the corporate level, we have Adobe Acrobat Professional 8 and I don't think I have enough pull to get them to upgrade to 9.  Any ideas of a v8 workaround?  Currently, I'm just appending them all in to 1 document, which works but doesn't present as nice as a Package or Portfolio would.

  • Excel 2010 Synchronize List with SharePoint List using VBA

    I have used and loved the interaction between Excel and SharePoint for many generations of both solutions.  It's a wonderful opportunity to integrate the familiarity and simplicity of Excel (formatting, ease of use, availability) with the data storage
    and centralized list capabilities of SharePoint.  Right?
    When upgrading to Excel 2010, I have noticed with much dismay that much of the inherent easy to use features of previous versions were effectively stripped from this newest version.  Much research, time and energy has been spent working around and resolving
    the deficiency.  One Microsoft based article,
    http://support.microsoft.com/kb/930006, has provided the mechanics behind utilizing the "hidden" functionality... although, this capability to use VBA to create the synchronized list was available in previous versions.  However, once Microsoft
    published this article to this "hidden" functionality... I feel that the behavior should be supported by Microsoft in some way.  OK?
    Revised instructions to reproduce the problem:
    1. Create a SharePoint list with 20 dummy records.
    - Note the List Name  ##LIST_NAME##
    - Note the View GUID  ##VIEW_GUID##
    - Note SharePoint Base URL  ##BASE_URL##
    2. REVISED... In Excel 2010, save the file as Compatible "Excel 97-2003 Workbook".  Close the file and reopen.  Create a connected table (ListObject) in Excel using the article above to the SharePoint list.  Use Sample VBA code
    below:
    Sub LinkedSharePointList()    
    ActiveSheet.ListObjects.Add SourceType:=xlSrcExternal,_
        Source:=Array(##BASE_URL## & "/_vti_bin", ##LIST_NAME##, _
        ##VIEW_GUID##), LinkSource:=True, Destination:=Range("A1")
    End Sub
    3. OOPS REVISED this item.  The problem is actually with ROW 21... So, update record on row 21... (no matter where the table is located... (if the "Destination" is "A1", then the problem is with ID=20, but if the Table is
    shifted down to say A12, then ID=9 on row 21).  Anyway... make a simple change to that record... and you'll see the ID immediately change.... as if it's a NEW record.  WEIRD!  Note: If the sheet is protected, then an error is displayed
    indicating that a "read-only" record cannot be updated (referring to the ID cell in column A for the current row). 
    4. Now "synchronize" the list with excel.  The former record is still in the list unchanged AND there is a NEW record in the list holding the changes.  There are a number of problems that seem to ONLY occur when something changes to ROW
    21.... Next, try to copy/paste multiple records across multiple rows that intersect with ROW 21.  Yikes!! 
    I look forward to hearing others' experience!
    Thanks!
    Mark

    Here are some things that you can try (change the code, where appropriate):
    Private Sub CreateList()
        Dim folder As folder
        Dim f As File
        Dim fs As New FileSystemObject
        Dim RowCtr As Integer
        RowCtr = 1
        Set folder = fs.GetFolder("http://excel-pc:43231/Shared Documents/Forms/") '<=Variable Location
        For Each f In folder.Files
           Cells(RowCtr, 1).Value = f.Name
           RowCtr = RowCtr + 1
        Next f
    End Sub
    Sub ListAllFile()
     Dim objFSO As Object
     Dim objFolder As Object
     Dim objFile As Object
     Dim pth As String
     Dim WBn As Workbook
     Dim ObCount As Long
     Dim FileNme As String
     Application.ScreenUpdating = False
     Set objFSO = CreateObject("Scripting.FileSystemObject")
     'Get the folder object associated with the directory
     Set objFolder = objFSO.GetFolder("\\excel-pc:43231\Shared Documents\Forms\")
    '** You'll need to specify your path here. By removing the http: from the path, the code liked it & found the folder. It wasn’t working previously ***
     pth = "http://excel-pc:43231/Shared Documents/Forms/"
    '** You'll need to specify your path here. The reason I’ve done this separately is because the path is not recognised otherwise when trying to specify it with workbook.open & using the value set for objFolder **
     ObCount = objFolder.Files.Count
    '** counts the number of files in the folder
     'Loop through the Files collection
     For Each objFile In objFolder.Files
     Nm1 = Len("http://excel-pc:43231/Shared Documents/Forms/")
    '** You'll need to specify your path here **
     Nm2 = Len(objFile) - Nm1
     FileNme = Right(objFile, Nm2)
    '** I’ve done this part to find out/set the file name**
     Set WBn = Workbooks.Open(pth & FileNme, , , , Password:="YourPassword")
    '** opens the first file in the library – if there is no password, the remove everything from - , , , , Password:="Password1" – leaving the close bracket ‘)’
     Application.ScreenUpdating = False
    '** optional – you can leave the screen updating on
    '<< Your coding here>>
    '** The file is now open. Enter whatever code is specific to your spreadsheets.
     Next
    '** goes to next file within your sharepoint folder
    End Sub
    Sub SharePoint()
    Dim xlFile As String, xlFullFile As String
    Dim xlApp As Excel.Application
    Dim wb As Workbook
    xlFile = "\\excel-pc:43231\Shared Documents"
    'http://excel-pc:43231/Shared Documents/
    '****----denotes the path.(i.e) u give the path as windows search.Don't use "\" at the end.
    'In the sharepoint path %20 denotes space.so u remove that and use space .
    Set xlApp = New Excel.Application
    xlApp.Visible = True
    xlFullFile = GetFullFileName(xlFile, "Book") 'ANZ denotes starting characters of the file.
    xlFile = xlFile & "\" & xlFullFile
    Set wb = xlApp.Workbooks.Open(xlFile, , False)
    'Once the workbook is opened u can do ur code here
    wb.Close False
    End Sub
    Function GetFullFileName(strfilepath As String, _
    strFileNamePartial As String) As String
    Dim objFS As Variant
    Dim objFolder As Variant
    Dim objFile As Variant
    Dim intLengthOfPartialName As Integer
    Dim strfilenamefull As String
    Set objFS = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFS.GetFolder(strfilepath)
    'work out how long the partial file name is
    intLengthOfPartialName = Len(strFileNamePartial)
    For Each objFile In objFolder.Files 'Instead of specifying the starting characters of the file you can directly loop through all files in the folder .
    'Test to see if the file matches the partial file name
    If Left(objFile.Name, intLengthOfPartialName) = strFileNamePartial Then
    'get the full file name
    strfilenamefull = objFile.Name
    Exit For
    Else
    End If
    Next objFile
    Set objFolder = Nothing
    Set objFS = Nothing
    'Return the full file name as the function's value
    GetFullFileName = strfilenamefull
    End Function
    Sub SrchForFiles()
    ' Searches the selected folders and sub folders for files with the specified (xls) extension.
    'ListTheFiles 'get the list of all the target XLS files on the SharePoint Directory
    Dim i As Long, z As Long, Rw As Long, ii As Long
    Dim ws As Worksheet, dd As Worksheet
    Dim y As Variant
    Dim fldr As String, fil As String, FPath As String
    Dim LocName As String
    Dim FString As String
    Dim SummaryWB As Workbook
    Dim SummaryWS As Worksheet
    Dim Raw_WS As Worksheet
    Dim LastRow As Long, FirstRow As Long, RowsOfData As Long
    Dim UseData As Boolean
    Dim FirstBlankRow As Long
    'grab current location for later reference, for where to paste final data
    Set SummaryWB = Application.ActiveWorkbook
    Set SummaryWS = Application.ActiveWorkbook.ActiveSheet
    y = "xls"
    fldr = "\\excel-pc:43231\Shared%20Documents\Forms\AllItems.aspx"
    FirstBlankRow = 2
    'asd is a 1-D array of files returned
    asd = ListFiles(fldr, True)
    Set ws = Excel.ThisWorkbook.Worksheets(1) 'list of files
    ws.Activate
    ws.Range("A1:Z100").Select
    Selection.Clear
    On Error GoTo 0
    For ii = LBound(asd) To UBound(asd)
    Debug.Print Dir(asd(ii))
    fil = asd(ii)
    'open the file and grab the data
    Application.Workbooks.Open (fil), False, True
    'Get file path from file name
    FPath = Left(fil, Len(fil) - Len(Split(fil, "\")(UBound(Split(fil, "\")))) - 1)
    'Get file information
    If Left$(fil, 1) = Left$(fldr, 1) Then
    If CBool(Len(Dir(fil))) Then
    z = z + 1
    ws.Cells(z + 1, 1).Resize(, 6) = _
    Array(Dir(fil), LocName, RowsOfData, Round((FileLen(fil) / 1000), 0), FileDateTime(fil), FPath)
    DoEvents
    With ws
    .Hyperlinks.Add .Range("A" & CStr(z + 1)), fil
    '.FoundFiles(i)
    End With
    End If
    End If
    'Workbooks.Close 'Fil
    Application.CutCopyMode = False 'Clear Clipboard
    Workbooks(Dir(fil)).Close SaveChanges:=False
    Next ii
    With ws
    Rw = .Cells.Rows.Count
    With .[A1:F1]
    .Value = [{"Full Name","Location","Rows of Data","Kilobytes","Last Modified", "Path"}]
    .Font.Underline = xlUnderlineStyleSingle
    .EntireColumn.AutoFit
    .HorizontalAlignment = xlCenter
    End With
    .[G1:IV1 ].EntireColumn.Hidden = True
    On Error Resume Next
    'Range(Cells(Rw, "A").End(3)(2), Cells(Rw, "A")).EntireRow.Hidden = True
    Range(.[A2 ], Cells(Rw, "C")).Sort [A2 ], xlAscending, Header:=xlNo
    End With
    End Sub
    Function ListFiles(ByVal Path As String, Optional ByVal NestedDirs As Boolean) _
    As String()
    Dim fso As New Scripting.FileSystemObject
    Dim fld As Scripting.folder
    Dim fileList As String
    ' get the starting folder
    Set fld = fso.GetFolder(Path)
    ' let the private subroutine do all the work
    fileList = ListFilesPriv(fld, NestedDirs)
    ' (the first element will be a null string unless the first ";" is removed)
    fileList = Right(fileList, Len(fileList) - 1)
    ' convert to a string array
    ListFiles = Split(fileList, ";")
    End Function
    ' private procedure that returns a file list
    ' as a comma-delimited list of files
    Function ListFilesPriv(ByVal fld As Scripting.folder, _
    ByVal NestedDirs As Boolean) As String
    Dim fil As Scripting.File
    Dim subfld As Scripting.folder
    ' list all the files in this directory
    For Each fil In fld.Files
    'If UCase(Left(Dir(fil), 5)) = "MULTI" And fil.Type = "Microsoft Excel Worksheet" Then
    If fil.Type = "Microsoft Excel Worksheet" Then
    ListFilesPriv = ListFilesPriv & ";" & fil.Path
    Debug.Print fil.Path
    End If
    Next
    ' if requested, search also subdirectories
    If NestedDirs Then
    For Each subfld In fld.SubFolders
    ListFilesPriv = ListFilesPriv & ListFilesPriv(subfld, NestedDirs)
    Next
    End If
    End Function
    Finally . . .
    Sub ListFiles()
        Dim folder As Variant
        Dim f As File
        Dim fs As New FileSystemObject
        Dim RowCtr As Integer
        Dim FPath As String
        Dim wb As Workbook
        RowCtr = 1
        FPath = "http://excel-pc:43231/Shared Documents"
        For Each f In FPath
        'Set folder = fs.GetFolder("C:\Users\Excel\Desktop\Ryan_Folder")
        'For Each f In folder.Files
           Cells(RowCtr, 1).Value = f.Name
           RowCtr = RowCtr + 1
        Next f
    End Sub
    Sub test()
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFolder = objFSO.GetFolder("C:\Users\Excel\Desktop\Ryan_Folder")
        'Set colSubfolders = objFolder.SubFolders
        'For Each objSubfolder In colSubfolders
           Cells(RowCtr, 1).Value = f.Name
           RowCtr = RowCtr + 1
        'Next
    End Sub
    Ryan Shuell

  • Using VBA to generate varibale worksheets in BEx Report

    Hi Gurus,
    i got an BEx Analyzer report (BW 3.5) in Excel. It shows all orders generated by the customers. In the table we can see the customer number, customer name, some attributes and the sales key figures.
    For Example:
    10000, Peter, ..................., 20 EUR
    10023, Clark, ..................., 20 EUR
    12200, Bert, ..................., 20 EUR
    13200, Erny, ..................., 20 EUR
    etc.
    Now i want that Excel takes each customer number and creates a new worksheets - each with the customer number in it / or name. As the number of customers is different each week it should be flexible. Any idea with VBA? I know that i can place in SAPBExonrefresh some coding.
    Regards,
    Memoli

    Hi Memoli,
    i think i now what you want. Use the following code but check the steps:
    1. Run your query in Analyzer.
    2. Move result area to top left but hide alle headers, texts, free characteristics etc. Only the table should be available - that with customer and data fields. Better change to table view in query designer or local view.
    2. Your query should start in field A1 or A2. If you want leave a header ampty on top and write customer number in this field - in this case your table starts in A2.
    3. Delete all worksheets and leave the one with the query. Name it "Customer".
    4. Insert a button by using VBA toolbar. Doubleclick and paste following code in editor:
    Sub TabAnlegen()
       Dim wks As Worksheet
       Dim iRow As Integer
       Application.ScreenUpdating = False
       Set wks = Worksheets("Customer")
       iRow = 2
       Do Until IsEmpty(wks.Cells(iRow, 1))
          Worksheets.Add after:=Worksheets(Worksheets.Count)
          ActiveSheet.Name = wks.Cells(iRow, 1).Value
          iRow = iRow + 1
       Loop
       wks.Select
       Application.ScreenUpdating = True
    End Sub
    After that. Run your query and press the button.
    Regards,
    Adem

  • [b]Tutorial:[/b] Simplify Developing OLE Automation Code Using VBA

    INTRODUCTION
    Automating Office applications from Oracle Forms can be a tedious, frustrating, and time-consuming process. Because the OLE2 and CLIENT_OLE2 built-ins do not validate the automation commands that they relay, code that compiles without errors often dies at runtime with a not-so-helpful error code. This tutorial will demonstrate how to simplify the development of automation code using a tool that ships with all Microsoft Office editions -- the Visual Basic for Applications (VBA) IDE.
    The VBA IDE, a core Office component, is a full-fledged development environment featuring code completion, basic syntax highlighting, context-driven help and a runtime debugger. Its Object Browser provides a convenient means of browsing the Word object model, as well as searching by keyword.
    For those who may not interested in following this tutorial in detail, I would like to stress the usefulness of the Object Browser as a tool for inspecting the functions supported by OLE server applications and, perhaps more importantly, valid values for function arguments. Whether/not anyone buys the assertion that starting with VBA prototypes is far more productive than pounding out OLE2 code from the very start, they will find the Object Browser invaluable as a reference -- I rely on it exclusively for this sort of documentation.
    A BRIEF INTRODUCTION TO THE VBA IDE & THE OBJECT BROWSER UTILITY
    Try this:
    1. Open Word
    2. Launch the VBA IDE by pressing <Alt><F11>
    3. Open the Object Browser by pressing <F2>
    The Object Browser allows you to visually navigate Word's class hierarchy. Its user interface is a bit crowded, so controls are unlabeled. Hovering the mouse cursor above a control will display a tooltip explaining that control's purpose. The browser's scope can be narrowed by using the Project/Library combo. Typing a keyword or substring in the Search Text combo and clicking on the Search button will cause all classes/members whose name contains the specified search text to be listed in the Search Results pane. Selecting an item from this list will update the two panes below it, showing the selected class, and its members. Beneath the Classes and Members panes is an untitled pane, gray in color, which displays details for the selected class/member, including hyperlinks to relevant information such as arguments, their types and allowable values. If Visual Basic Help is installed, pressing <F1> will display help on a selected class/member. (This feature can be installed from your Office install CD, if necessary.)
    NOTE: While it is possible to cut-and-paste the code examples that follow, I highly recommend that they be typed in by hand. Doing so will provide a better understanding of how the IDE's code completion behaves. Use code completion most efficiently by not using the mouse or <Enter> key when selecting from completion lists. Instead, just type enough letters to select the desired list element, then continue along as if you had typed the entire element, typing the next operator in your statement. It really is slick!
    HELLO WORLD - VBA-STYLE
    1. Open Word
    2. Launch the VBA IDE by pressing <Alt><F11>
    3. Select Module from the Insert menu.
    4. In the blank area that appears, enter the following code:
      Public Sub HelloWorld()
          Documents.Add
          Selection.TypeText ("Hello, world!")
      End Sub5. Press <F5> to run the code.
    If you switch back to Word by pressing <Alt><F11>, there should appear a newly-created document containing the text Hello, world!.
    A MORE AMBITIOUS EXAMPLE
    In this example, we will launch Word, type some text, and alter its formatting. For the purposes of this tutorial, consider it the process we wish to automate from within Forms.
    1. If Word is running, close it.
    2. Open any Office application except Word, such as Excel, Outlook or PowerPoint
    3. Launch the VBA IDE by pressing <Alt><F11>.
    4. Select References from the Tools menu -- a dialog should pop up.
    5. From within this dialog, locate and select Microsoft Word <version> Object Library, then click OK.
    6. Select Module from the Insert menu.
    7. In the blank area that appears, enter the following code:
    Public Sub LaunchWord()
        Dim app As Word.Application
        Set app = CreateObject("Word.Application")
        app.Visible = True                          '!!! IMPORTANT !!!
        app.Documents.Add
        With app.Selection
            .TypeText "This is paragraph 1."
            .TypeParagraph
            .TypeText "This is paragraph 2."
            .TypeParagraph
            .TypeText "This is paragraph 3."
        End With
        With ActiveDocument
            .Paragraphs(1).Range.Words(3).Bold = True
            .Paragraphs(2).Range.Words(3).Italic = True
            .Paragraphs(3).Range.Words(3).Underline = True
        End With
    End Sub8. Press <F5> to run the code.
    A new Word session should have been launched. Switch to it, to view the results of our handiwork!
    TAILORING VBA CODE INTENDED FOR OLE2 CONVERSION
    Now, things get a bit uglier. The code listed above gives a good idea of how concise VBA code can be, but With blocks and chained object references do not translate readily into OLE2 code. Here's the same process, rewritten in a more OLE2-friendly style. Note the numerous intermediate object references that have been declared.
    Public Sub LaunchWord()
        Dim app As Word.Application
        Dim doc As Word.Document
        Dim docs As Word.Documents
        Dim pars As Word.Paragraphs
        Dim par As Word.Paragraph
        Dim wrds As Word.Words
        Dim sel As Word.Selection
        Dim rng As Word.Range
        Set app = CreateObject("Word.Application")
        app.Visible = True                          '!!! IMPORTANT !!!
        Set doc = app.Documents.Add
        Set sel = app.Selection
        sel.TypeText "This is paragraph 1."
        sel.TypeParagraph
        sel.TypeText "This is paragraph 2."
        sel.TypeParagraph
        sel.TypeText "This is paragraph 3."
        Set pars = doc.Paragraphs
        'select third word of first paragraph and make it bold
        Set par = pars.Item(1)
        Set rng = par.Range
        Set wrds = rng.Words
        Set rng = wrds.Item(3)
        rng.Bold = True
        'select third word of second paragraph and italicize it
        Set par = pars.Item(2)
        Set rng = par.Range
        Set wrds = rng.Words
        Set rng = wrds.Item(3)
        rng.Italic = True
        'select third word of second paragraph and underline it
        Set par = pars.Item(3)
        Set rng = par.Range
        Set wrds = rng.Words
        Set rng = wrds.Item(3)
        rng.Underline = True
    End Sub
    TRANSFORMATION: CONVERTING VBA CODE INTO PL/SQL
    Here is the PL/SQL counterpart to our previous VBA routine. Compare printouts of the two and note their similarities. Notice the need for argument lists -- this causes the code to fluff up quite a bit, and really interferes with readability.
    PROCEDURE LAUNCH_WORD IS
      v_app OLE2.OBJ_TYPE;     -- Application
      v_doc OLE2.OBJ_TYPE;     -- Document
      v_docs OLE2.OBJ_TYPE;    -- Documents collection
      v_pars OLE2.OBJ_TYPE;    -- Paragraphs collection
      v_par OLE2.OBJ_TYPE;     -- Paragraph
      v_wrds OLE2.OBJ_TYPE;    -- Words collection
      v_sel OLE2.OBJ_TYPE;     -- Selection
      v_rng OLE2.OBJ_TYPE;     -- Range
      v_args OLE2.LIST_TYPE;   -- OLE2 argument list
    BEGIN
      /* launch Word and MAKE IT VISIBLE!!! */ 
        v_app := OLE2.CREATE_OBJ('Word.Application');
        OLE2.SET_PROPERTY(v_app, 'Visible', TRUE);
      /* initialize key object references */ 
        v_docs := OLE2.GET_OBJ_PROPERTY(v_app, 'Documents');
        v_doc := OLE2.INVOKE_OBJ(v_docs, 'Add');
        v_sel := OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');
      /* type first paragraph */
        v_args := OLE2.CREATE_ARGLIST;
        OLE2.ADD_ARG(v_args, 'This is paragraph 1.');
        OLE2.INVOKE(v_sel, 'TypeText', v_args);
        OLE2.DESTROY_ARGLIST(v_args);
        OLE2.INVOKE(v_sel, 'TypeParagraph');
      /* type second paragraph */
        v_args := OLE2.CREATE_ARGLIST;
        OLE2.ADD_ARG(v_args, 'This is paragraph 2.');
        OLE2.INVOKE(v_sel, 'TypeText', v_args);
        OLE2.DESTROY_ARGLIST(v_args);
        OLE2.INVOKE(v_sel, 'TypeParagraph');
      /* type third paragraph */
        v_args := OLE2.CREATE_ARGLIST;
        OLE2.ADD_ARG(v_args, 'This is paragraph 3.');
        OLE2.INVOKE(v_sel, 'TypeText', v_args);
        OLE2.DESTROY_ARGLIST(v_args);
      /* set reference to Paragraphs collection */
        v_pars := OLE2.GET_OBJ_PROPERTY(v_doc, 'Paragraphs');
      /* select third word of first paragraph and make it bold */
        v_args := OLE2.CREATE_ARGLIST;
        OLE2.ADD_ARG(v_args, 1);
        v_par := OLE2.INVOKE_OBJ(v_pars, 'Item', v_args);
        OLE2.DESTROY_ARGLIST(v_args);
        v_rng := OLE2.GET_OBJ_PROPERTY(v_par, 'Range');
        v_wrds := OLE2.GET_OBJ_PROPERTY(v_rng, 'Words');
        v_args := OLE2.CREATE_ARGLIST;
        OLE2.ADD_ARG(v_args, 3);
        v_rng := OLE2.INVOKE_OBJ(v_wrds, 'Item', v_args);
        OLE2.SET_PROPERTY(v_rng, 'Bold', TRUE);
      /* select third word of second paragraph and italicize it */
        v_args := OLE2.CREATE_ARGLIST;
        OLE2.ADD_ARG(v_args, 2);
        v_par := OLE2.INVOKE_OBJ(v_pars, 'Item', v_args);
        OLE2.DESTROY_ARGLIST(v_args);
        v_rng := OLE2.GET_OBJ_PROPERTY(v_par, 'Range');
        v_wrds := OLE2.GET_OBJ_PROPERTY(v_rng, 'Words');
        v_args := OLE2.CREATE_ARGLIST;
        OLE2.ADD_ARG(v_args, 3);
        v_rng := OLE2.INVOKE_OBJ(v_wrds, 'Item', v_args);
        OLE2.SET_PROPERTY(v_rng, 'Italic', TRUE);
      /* select third word of second paragraph and underline it */
        v_args := OLE2.CREATE_ARGLIST;
        OLE2.ADD_ARG(v_args, 3);
        v_par := OLE2.INVOKE_OBJ(v_pars, 'Item', v_args);
        OLE2.DESTROY_ARGLIST(v_args);
        v_rng := OLE2.GET_OBJ_PROPERTY(v_par, 'Range');
        v_wrds := OLE2.GET_OBJ_PROPERTY(v_rng, 'Words');
        v_args := OLE2.CREATE_ARGLIST;
        OLE2.ADD_ARG(v_args, 3);
        v_rng := OLE2.INVOKE_OBJ(v_wrds, 'Item', v_args);
        OLE2.SET_PROPERTY(v_rng, 'Underline', TRUE);
    END;
    REFACTORING FOR REUSABILITY AND READABILITY
    While the previous procedure runs without errors, it suffers from poor readability which, in turn, makes it difficult to maintain. Here, we address those issues by moving repetetive low-level operations into separate procedures.
      PROCEDURE LAUNCH_WORD IS
        v_app OLE2.OBJ_TYPE;    -- Application
        v_doc OLE2.OBJ_TYPE;    -- Document
        v_docs OLE2.OBJ_TYPE;   -- Documents collection
        v_sel OLE2.OBJ_TYPE;    -- Selection
        v_args OLE2.LIST_TYPE;  -- OLE2 argument list
      BEGIN
        /* launch Word and MAKE IT VISIBLE!!! */ 
          v_app := OLE2.CREATE_OBJ('Word.Application');
          OLE2.SET_PROPERTY(v_app, 'Visible', TRUE);
        /* create a new Word document */ 
          v_docs := OLE2.GET_OBJ_PROPERTY(v_app, 'Documents');
          v_doc := OLE2.INVOKE_OBJ(v_docs, 'Add');
          v_sel := OLE2.GET_OBJ_PROPERTY(v_app, 'Selection');
        /* add a few paragraphs */
          PRINT_PARAGRAPH(v_sel, 'This is paragraph 1.');
          PRINT_PARAGRAPH(v_sel, 'This is paragraph 2.');
          PRINT_PARAGRAPH(v_sel, 'This is paragraph 3.');
        /* apply formatting */
          APPLY_FORMATTING(v_doc, 1, 3, 'Bold', TRUE);
          APPLY_FORMATTING(v_doc, 2, 3, 'Italic', TRUE);
          APPLY_FORMATTING(v_doc, 3, 3, 'Underline', TRUE);
      END;
      PROCEDURE APPLY_FORMATTING(
        v_doc OLE2.OBJ_TYPE,
        v_paragraph_num NUMBER,
        v_word_num NUMBER,
        v_attribute VARCHAR2,
        v_value BOOLEAN) IS
        v_pars OLE2.OBJ_TYPE;   -- Paragraphs collection
        v_par OLE2.OBJ_TYPE;    -- Paragraph
        v_wrds OLE2.OBJ_TYPE;   -- Words collection
        v_rng OLE2.OBJ_TYPE;    -- Range
        v_args OLE2.LIST_TYPE;  -- OLE2 argument list
      BEGIN
        /* set reference to Paragraphs collection */
          v_pars := OLE2.GET_OBJ_PROPERTY(v_doc, 'Paragraphs');
        /* get specified paragraph */   
          v_args := OLE2.CREATE_ARGLIST;
          OLE2.ADD_ARG(v_args, v_paragraph_num);
          v_par := OLE2.INVOKE_OBJ(v_pars, 'Item', v_args);
          OLE2.DESTROY_ARGLIST(v_args);
        /* get words for specified paragraph */
          v_rng := OLE2.GET_OBJ_PROPERTY(v_par, 'Range');
          v_wrds := OLE2.GET_OBJ_PROPERTY(v_rng, 'Words');
        /* apply formatting to word found at specified index */
          v_args := OLE2.CREATE_ARGLIST;
          OLE2.ADD_ARG(v_args, v_word_num);
          v_rng := OLE2.INVOKE_OBJ(v_wrds, 'Item', v_args);
          OLE2.SET_PROPERTY(v_rng, v_attribute, v_value);
      END;
      PROCEDURE PRINT_PARAGRAPH(v_sel OLE2.OBJ_TYPE, v_text VARCHAR2) IS
        v_args OLE2.LIST_TYPE;
      BEGIN
        v_args := OLE2.CREATE_ARGLIST;
        OLE2.ADD_ARG(v_args, v_text);
        OLE2.INVOKE(v_sel, 'TypeText', v_args);
        OLE2.DESTROY_ARGLIST(v_args);
        OLE2.INVOKE(v_sel, 'TypeParagraph');
      END;
    CONCLUSION
    It is my hope that this tutorial, despite it's introductory nature, has demonstrated the value of the VBA IDE, the ease with which automation processes can be prototyped using VBA, the noticeable similarity between VBA automation routines and their Forms PL/SQL counterparts, and the advantages of testing automation processes within the VBA IDE. Please feel free to follow up with any specific questions or concerns you may have.
    Thanks,
    Eric Adamson
    Lansing, Michigan
    FINAL NOTE: These examples use the OLE2 built-in, and will operate correctly when called from forms running in the Form Builder OC4J. Deploying them to an Oracle Application Server will launch Word on the server itself (if available), which is usually not the developer's intent! Automating Word client-side via web forms requires adding WebUtil support. Adapting the code for WebUtil is trivial -- just replace all instances of OLE2 with CLIENT_OLE2. Adapting forms for WebUtil and configuring OLE support into your Oracle Application Server, however, are beyond the scope of this tutorial.
    REVISION HISTORY
    This promises to be something of a 'living document'. I've snuck changes through without comment in the past, but in the future, I'll try to document significant changes here.
    2006-08-21
      * Prefaced boring subject line with text: 'Tutorial:' to clarify purpose
      * Added emphasis on value of Object Browser as a reference

    Thanks James, for your kind words. I do hope this information will help folks out. I honestly believe that tinkering around in the VBA IDE will prove highly gratifying for automation developers. It can be assured that learning to make Word jump through hoops is much more straight-forward in this environment. I'm not one for mottos, but if I were pressed for a cheesy motto, I would say: First, make it work. Then, make it work in Oracle!
    Once the idea has sunk in, that Visual Basic routines for automating Word are exact analogs to their OLE2 counterparts, we can remove keywords like Oracle and PL/SQL from our Google searches on Word automation which, at least in this context, are the proverbial kiss of death. Suddenly we find ourselves liberated by the possibility of steal-, ahem... borrowing ideas from the Visual Basic* community!
    As for links, my link of choice is invariably http://groups.google.com -- if you don't already use it at least ten times a day, you must try it. This is the venerable USENET archive, including the holdings of now-extinct DejaNews. Another possible site of interest is http://word.mvps.org/FAQs/MacrosVBA, which may serve as a good starting point for those who wish to learn how to do fancy tricks with Word using VBA.
    If these links don't prove immediately helpful, please feel free to give specifics on the sort of operations you are interested in automating, and I'll see if I can post an example that addresses it.
    Regards,
    Eric Adamson
    Lansing, Michigan
    PS: I do hope, as people read my posts, with every other acronym being VBA, that they are not mistakenly hearing a call to learn Visual Basic. I say this, not because I believe learning VB would be a Bad Thing, but because I assume that few of us feel we have the time to learn a new programming language. Despite having come to the Oracle camp already knowing VB/VBA, and having acquired a fair bit of experience with automating Office applications as an Access developer, I remain confident that what I am suggesting people attempt does not rise to the level of learning a language. What I am suggesting is that they learn enough of the language to get by.
    *VB vs. VBA
    Just a quick word on this, as readers may wonder why I seem to use these terms interchangeably. Visual Basic (VB) can refer to either a development platform or a programming language. Visual Basic for Applications (VBA) is a language -- more precisely, it is a subset of the Visual Basic language. One purchases VB, usually quite intentionally. VBA is included with Microsoft Office, as is VBA's development environment, the VBA IDE. The key distinction between VB and VBA is that VBA cannot be used to create self-contained executables. Rather, VBA relies on VBA-enabled applications, such as Microsoft Office applications, to serve as a container for VBA code, and to provide a runtime environment for that code. For the purposes of discussing OLE Automation, VB and VBA are quite interchangeable.

  • 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

  • Acrobat Pro 7 quits when creating bookmarks

    I can only go up to Acrobat 7 on my Mac unless I upgrade from OS 10.3.9. PDFs create fine. Create bookmark by highlighting text and hit command-b. Repeat a few times. Save document and Acrobat quits. Original document is Word 2004 for Mac 11.5.0. I suspect Acrobat doesn't like the hidden TOC data in the headings I am using for bookmarks. BUT, this never happened with Distiller 4.0, the last version I used extensively. Anybody got a fix? I have a 1GHz G4 eMac with 768MB ram.

    Evidently I mispoke, it works on 10.4. I thought I had been using it on X.3.9.Because I have one hard drive  that use X.3.9. Ther are some updates to 7.0 though. Make sure you your using the most up to date version.  Sorry for misleading you.

  • Is it possible to add a button to the right-click context menu for a user in Outlook 2010 using VBA?

    I've tried many things and read up quite a bit but I cannot figure this out.
    I cannot create an add-in so I have to use VBA.
    I want to add a a button to the right-click context menu when I right-click on a user. Is this possible?

    Hello,
    Yes, it is possible to customize the context menu in Outlook. See
    Customizing Context Menus in Office 2010 for more information.
    But VBA doesn't allow to customize the Fluent UI in Outlook, you need to develop an add-in instead.

  • 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

  • RFC call from Excel using VBA

    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 AM

    Hello 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

Maybe you are looking for