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

Similar Messages

  • 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/

  • Help using VBA to auto generate PDF using PDFMaker

    I am using Adobe 9 Pro ( v9.2.0) and would to automate the building of PDFs from Excel.
    I have an Excel document with a [Main] page that has hyperlinks to the multiple worksheets in the document.
    I can manually select the [Main] sheets + all other sheets and choose SaveAs [Adobe PDF] and it builds a single PDF with all the sheets and includes the Hyperlinks so I can go from the [Main] page to each of the individual pages ( worksheets ) and back.
    I would like to automate this build ( as I have to create 100+ PDFs per month ) using VBA.
    In the Excel IDE, I added reference to [AdobePDFMakerForOffice] and the code below (which I copied from another post on this forum ) but it only creates one page ( active sheet ) !
    Can anyone help with what I am doing wrong ?
    Cannot find any documentation on the Usage or Example on the subject.
    Thanks Aubrey
    Sub rxSaveAsPDF(pSaveAs)
        Dim xx As Integer, retVal As Long
        Dim appAdobe As AdobePDFMakerForOffice.PDFMaker
        Dim appSettings As AdobePDFMakerForOffice.ISettings
        For xx = 1 To Application.COMAddIns.Count
            If InStr(UCase(Application.COMAddIns(xx).Description), "PDFMAKER") > 0 Then Set appAdobe = Application.COMAddIns(xx).Object
        Next xx
        appAdobe.GetCurrentConversionSettings appSettings
        appSettings.OutputPDFFileName = pSaveAs
        appSettings.ConvertAllPages = True
        appSettings.CreateFootnoteLinks = True
        appSettings.CreateXrefLinks = True
        appSettings.AddTags = False
    '    appSettings.ShouldShowProgressDialog = True
    '    appSettings.ViewPDFFile = True
        appSettings.FitToOnePage = False
        appSettings.PromptForSheetSelection = False
        appSettings.AddLinks = True
        appSettings.AddTags = True
        appSettings.AddBookmarks = True
        appSettings.AdvancedTagging = True
        appAdobe.CreatePDFEx appSettings, 0
        Set appAdobe = Nothing
        Set appSettings = Nothing
    End Sub

    Moved to Acrobat SDK

  • BEx Analyzer: using VBA without using workbooks ???

    Hi,
    is there any way to use VBA-scripts, while not  using workbooks ?
    short description of my problem:
    I want to place an button in <i>every Querie</i> (not only in workbooks), which shows an short description of the query.
    /edit
    Or does anyone knows an other way to solv my problem (e.g. using an User Exit,...)?
    Kind regards
    Sebastian
    Message was edited by:
            Sebastian Bellmann

    Thanks for answering,
    but that's not what i'm searching for.
    Now a more detailed description of my probelm.
    I'm searching for a mechanism to place (automaticly) a Text in an empty row  of a Query ( e.g. to display "That is a Testquerie don't use " or to display a Help message ).
    To solv this I found a couple of functions (e.q. UPF_EXCEL_AFTER_DATA_PUT_01 or RH_START_EXCEL_WITH_DATA) but they don't work .
    Maybe I'm just to stupid to handle them right...
    Hope somebody can help me.
    Kind regards
    Sebastian Bellmann

  • How to retrieve workbook's "Last Refreshed" value using VBA?

    Does anyone know how to retrieve a BEx workbook's "Last Refreshed" value using VBA?
    What I've done is expand upon a colleague's existing Excel VBA solution to automatically log into SAP BEx and batch process (and also schedule) the running of multiple BEx reports. As each BEx report in the queue is processed, the results of the run are written to a "Results" worksheet -- indicating whether that BEx report was processed successfully or not. I'm pretty much done, and everything works like a charm.
    Except I have one little problem remaining: during the processing of each BEx report, the SAP BEx status dialog appears, giving the user the ability to cancel the processing of that particular report, if they so desire. If the user cancels, I want my "Results" worksheet to indicate that for that report.
    At first, I thought, okay, I'll just test the return value when calling the SAPBEX.XLA's SAPBEXrefresh function. That function's return value is supposed to return the number of errors that occurred after each time SAPBEXrefresh is fired -- normally it's 0 if everything runs okay. So surely, if the user cancels, there's got to be some sort of error and the return value of SAPBEXrefresh would be > 0, right? Nope, no such luck!
    Which brings me back to my question in this post -- I found out through my company's SAP consultant that, if the user hits cancel in the SAP BEx dialog, the "Last Refreshed" value will not change. Therefore, he told me, simply test the value of the "Last Refreshed" value before and after each BEx reports' run. If the "Last Refreshed" value doesn't change, then presto, you know the user canceled.
    This is where I'm stuck. How do you programmatically get the "Last Refreshed" value? Obviously, you could write VBA code to find the first cell in the BEx report with the text "Last Refreshed" and then get the value in the adjoining cell. The problem with that is, what if, for some stupid reason, there's another cell somewhere in the BEx report with the text, "Last Refreshed". There's no way I can be sure that I've really found the "Last Refreshed" value plugged in by BEx.
    I've been looking extensively in this forum for an answer, but haven't found any. It seems like there are a lot of SAP BEx experts here, and if anyone can help me out here, I would greatly appreciate it.
    Thank you.

    Well, it was a little circuitous, but I figured out the solution to my own question.
    I recalled I had read about the sapbexDebugPrint macro in sapbex.xla in one of Peter Knoer's posts in this forum. So I thought, maybe I can use that to get the before and after refresh values of "Last Refreshed" in the workbook. Well, I was half-right: I could only use sapbexDebugPrint to get the workbook's after-refresh values of "Last Refreshed".
    But it didn't matter!
    As long as the after-refresh value of the workbook's "Last Refreshed" value was later than the after-refresh value of the previous workbook in the processing queue, I knew the refresh was successful and the user didn't cancel. There were some other logic permutations I had to factor in, but basically that was the answer.
    Here are snippets of my code from the main procedure, for anyone's who interested:
                '   **** Refresh query ************************************
                ' Get the previous "Last Refreshed" value
                ' We're going to need to compare this to the "Last Refreshed" value
                ' after running SAPBEXrefresh function to trap the possibility of
                ' the user canceling via the SAPBEx status dialog box
                PrevLastRefr = GetLastRefreshed()
                ' Reactivate the source workbook, just in case
                SourceWorkbook.Activate
                 RefreshRetVal% = Application.Run("SAPBEX.XLA!SAPBEXrefresh", True, , False)
                If RefreshRetVal% <> 0 Then
                    blnProcessingErr = True
                End If
                ' Get the current "Last Refreshed" value and compare it to the previous value
                CurrLastRefr = GetLastRefreshed()
                If CurrLastRefr = "NOT FOUND" Then
                    ' Refresh canceled
                    blnProcessingCanceled = True
                Else    ' We found a valid current "Last Refreshed" value
                    If PrevLastRefr = "NOT FOUND" Then
                        ' Refresh okay
                        blnProcessingCanceled = False
                    Else
                        If CDate(CurrLastRefr) > CDate(PrevLastRefr) Then
                            ' Current "Last Refreshed" value is later than previous value,
                            ' so refresh okay
                            blnProcessingCanceled = False
                        Else
                            ' Refresh canceled
                            blnProcessingCanceled = True
                        End If
                    End If
                End If
                ' Reactivate the source workbook, just in case
                SourceWorkbook.Activate
    And here's my function which retrieves the "Last Refreshed" value by calling sapbexDebugPrint macro in sapbex.xla:
    Function GetLastRefreshed() As Variant
    ' Get the SAP BEx "Last Refreshed" value by calling
    ' SAPBEx.xla's sapbexDebugPrint procedure and creating
    ' the special diagnostic workbook.
    On Error GoTo GetLastRefreshed_Error
        Dim TextCell As Range
        Dim TextCellAddr$
        Dim TextCellRow%, TextCellCol%
        Dim LastRefreshedVal As Variant
        Dim NumWorkbooks%
        ' Initialize
        GetLastRefreshed = "NOT FOUND"
        LastRefreshedVal = "NOT FOUND"
        ' Turn off screen updating until the end
        Application.ScreenUpdating = False
        ' Get the number of currently open workbooks
        NumWorkbooks% = Workbooks.Count
        ' Call the SAPBEx.xla's sapbexDebugPrint procedure
        ' This'll create a diagnostic workbook with all the information
        ' about the BEx query that was previously refreshed
        Application.Run "SAPBEX.XLA!sapbexDebugPrint"
        ' Let's double-check that the diagnostic workbook actually
        ' got created
        ' If there's any error at this point or if the number of workbooks
        ' isn't more than it was a moment ago, raise custom error
        If (Err.Number <> 0) Or (Not (Workbooks.Count > NumWorkbooks%)) Then
            Err.Raise vbObjectError + 513, , "sapbexDebugPrint failed to create the diagnostic workbook"
        End If
        ' We'll need to look at a worksheet named "E_T_TXT_SYMBOLS"
        ' in the diagnostic workbook
        ' If this worksheet doesn't exist, then we know that there
        ' was no previously refreshed query during this session
        ' (We could loop through the collection of worksheets in the workbook
        ' to see if that worksheet actually exists, but we'll use
        ' error handling to deal with this instead)
        ' Find the first cell in the "E_T_TXT_SYMBOLS" worksheet
        ' with the text "Last Refreshed"
        ' (If the worksheet doesn't exist, an error will be thrown...)
        Set TextCell = Sheets("E_T_TXT_SYMBOLS").Cells.Find(What:="Last Refreshed", _
                    LookIn:=xlValues)
        If TextCell Is Nothing Then
            ' Can't find the cell, so we know the user had canceled during previous refresh
            LastRefreshedVal = "NOT FOUND"
        Else
            ' Found the cell, now we're in business
            TextCellAddr$ = TextCell.Address ' $F$11
            TextCellRow% = CInt(Mid(TextCellAddr$, InStr(2, TextCellAddr$, "$") + 1))
            TextCellCol% = ColRef2ColNo(Mid(TextCellAddr$, 2, InStr(2, TextCellAddr$, "$") - 2))
            ' The cell with the "Last Refreshed" value is going to be 2 columns to the right
            LastRefreshedVal = Sheets("E_T_TXT_SYMBOLS").Cells(TextCellRow%, TextCellCol%).Offset(0, 2).Value
            ' Ensure the "Last Refreshed" value is a valid date/time
            If Not IsDate(LastRefreshedVal) Then LastRefreshedVal = "NOT FOUND"
        End If
    GetLastRefreshed_Exit:
        ' Err.Number -2147220991 is my custom raised error:
        ' "sapbexDebugPrint failed to create the diagnostic workbook"
        If Err.Number <> -2147220991 Then
            ' Close the diagnostic workbook and return Last Refreshed value
            Workbooks(ActiveWorkbook.Name).Close SaveChanges:=False
            GetLastRefreshed = LastRefreshedVal
        End If
        Application.ScreenUpdating = True   ' Turn on screen updating
        Exit Function
    GetLastRefreshed_Error:
        Select Case Err.Number
            Case 9  ' Subscript out of range (which means "E_T_TXT_SYMBOLS" worksheet doesn't exist)
                LastRefreshedVal = "NOT FOUND"
            Case Else
                MsgBox "Error encountered during getting Last Refreshed value." & vbCrLf & vbCrLf & _
               "Error: " & Err.Number & " - " & Err.Description, vbExclamation, gstrErrBoxTitle
        End Select
        Resume GetLastRefreshed_Exit
    End Function
    Like I said, the solution was a little circuitous, but it works!

  • 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

  • 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

  • Using VBA for loading Query data into Excel workbook

    Hi all.
    I want simply load data from BEx query into Excel Wortksheet using VBA because of report formats and footer section at the end of the results.
    Any code examples, tutorials, comments, suggestions will be regarded.
    thanx in advance,
    Gediminas

    The difficalty is that I don't know the number of rows report will return. And I need my footer only on LAST page of workbook.
    Another thing I can't imagine how to do by using standart BEx functionality is to design complex column header set (merged columns, sub-columns and etc.).

  • Using VBA in dimension sheets

    Hi
    I am trying to use VBA in a Dimension xls to update property columns from an external flat file.
    When the dim.xls file is open in administration, I can see the vba project (Worksheet in BpcFrameControl).
    I created a module then transferred some working code into it, however the module is not retained when I reopen the dim.xls.
    Has anyone successfully used vba in a dim.xls?
    My second question is regarding where the external flat file should sit, assuming I can get the code to work, I would prefer it to sit with the application folders so that anyone can use the macro, are there any issues with access rights? My application files are currently held on the sql server not the application server so I presume IIS is redirecting via the app server to the sql server.
    Many thanks
    Phil

    Phil,
    You can used
    =EVMNU("OPENFILE", "Opening file...","
    FILESERVER\Osoft\Webfolders\AppSetName\AppName\EEXCEL\REPORTS\ReportName.xlt")
    To open the stand alone file at one place and that can have all the code and this file can open the report you need or you can have the steup the other way around.
    This will handle yoor excel code.
    After this you will still need to run the SSIS, There is a bat command you can execute to run SSIS, This can get complicated if you have multserver MSAS install. but i have done this so i know you can do this.
    Post your questions and i will try to answer..
    Sam

  • 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;amp; Reporting: BEx Analyzer - Business Intelligence - SAP Library
    Best Regards,
    DB49

  • Using SQVI to generate report of open and released delivery schedule lines

    All,
    I'm using SQVI  to generate an excel spreadsheet for some buyers to show open released schedule lines because they are a 1 line item per scheduling agreement company.
    I used the logical database MEPOLDB instead of a table joint and pulled fields from EKKO(vendor, SA #,&purchasing group), EKPO(Material Number), EKEH(schedule line type), and EKET(delivery date, scheduled qty,previous qty).
    Does this sound like I'll get the results I want on paper as long as I use the right selection criteria, because the report I'm getting isn't quite what I expect? I am unable to identify which lines are authorized to ship vs. trade-off zone, planning, etc. in the report thus far.

    Hi Mark,
                 I have faced same requirement. I am not sure about transporting to TST and PROD. I done by this way.
    After generating SQVI program in DEV , I assigned that program  to a transaction and tested in DEV. Later i have regenarated SQVI in Production. then I assigned the generated Program to same transaction in DEV. And transported the Tcode assignment of program to Production..
    About authorization , if its not sensitive report, BASIS can restrict at transaction level.
    Regards,
    Ravi.

  • Use VBA and Excel to open Dreamweaver HTML (CS5), find and replace text, save and close

    I wish to use VBA and Excel to programmatically open numbered Dreamweaver HTML (CS5) and find and replace text in the code view of these files, save and close them.
    I have  5000 associations between Find: x0001 and Replace: y0001 in an Excel sheet.
    I have the VBA written but do not know how to open, close and save the code view of the ####.html files. Please ... and thank you...
    [email protected]

    This is actually the code view of file ####.html that I wish to find and replace programmatically where #### is a four digit number cataloguing each painting.... In 1995 I thought this was clever... maybe not so clever now :>)) Thank you for whatever you can do Rob!
    !####.jpg!
    h2. "Name####"
    Oils on acrylic foundation commercial canvas - . xx X xx (inches) Started
    Back of the Painting In Progress </p> </body> </html>
    Warmest regards,
    Phil the Forecaster, http://philtheforecaster.blogspot.ca/ and http://phils-market.blogspot.ca/

  • I want to use the Function Generator VI to send command signals through the NI 7344 motion controller. This will be a closed loop servo valve system. I want to be able to change from say a square wave to a sine wave on the fly. Idea's?

    I am going to run tests that require an actuator to move using various types of arbitrary waveforms such as sine or square. The NI 7344 is hooked to the UMI that is going through a driver for a servo valve. The loop is analog and it is closed. I have played with some of the examples but can't get it to work. I have used the function generator VI to generate a signal but I think I am using the wrong input VI to the motion control board. When I use what I have it moves the servo and then stops. It doesn't continually generate the signal.
    I would love to use the controls on the function generator vi to control frequency and amplitude ect. Any help or pointer would be helpful. Thank you in advance.

    Hello,
    I'm not clear on exactly how you want to use the generated data but I'm assuming they will be used as your target points.
    There's a built-in example for motion called 'One-Axis Contour Move.vi'. This example demonstrates how to provide your target points as 1-D array. All you need to do is to replace the input array with the output of the function generator. In order to have it run continuously, use a while loop. You can further program your application so that it'll change the waveform on the fly by monitoring the user interface but this might be little little tricky as you will need to reset the move and load the new generated points while keeping track of your current position.
    I hope this helps. Let me know if you have further questions regarding this
    application.
    Best regards,
    Yusuf C.
    Applications Engineering
    National Instruments

  • Using mathscript to generate multiple digital outputs for switch control

    Hello 
    I am new to this NI LV and a have kind of a basic question. I would like to use Mathscript to generate an array of bolean numbers which will be used to control the Digital I/O lines. I am using NI 6251 USB device and the Mathscript code runs well. But I have a problem using this array to control the Digital output. So I created a simple test programme where I set the DAQ assitant to generate 4 digital outputs(P0.0 ~ P0.3) and it gives error that  ".. number of channels in the data does not match the number of channels in the task..." (see attachment) . How can I solve this problem thank you.
    Attachments:
    K-9.jpg ‏36 KB

    looks like you did not initialize all 4 of the elements in the bool array....

  • Using JarSettings to generate EJB client jar, but supported classes missed

    Appreciated for any comments in advance.
    I am using @jarSetting to generate EJB client jar file from workshop 9.2. The remote method of EJB has one input parameter that is defined as an interface. The interface is included in client jar, but the implementation of this interface is not.
    Please advise how I can add the implementation of this interface to client jar?
    Best Regards,
    James

    Hi James,
    I believe the algorithm for creating the client jar is to simply inspect the EJB interfaces using reflection and to include all user defined classes and exceptions that are referenced by the interfaces. In your case, it sounds like a class is not being included because it is not directly referenced by one of the EJB interfaces.
    I think the client jar creation algorithm can be described as "best effort" and unfortunately, it does not always end up including all classes needed by the client. I would recommend you add the additional classes manually using the jar tool.
    - Matt

Maybe you are looking for