FlexPro
HistoryBase
Ingénierie
Formation
Téléchargements
Assistance FlexPro
Connaissance
Communauté
À propos de nous
Références
Emplois
Contact général
Liste des revendeurs
Assistance FlexPro
FR
DE
EN
Porte-plaquette
Produits et solutions
Support et téléchargements
Entreprise
Magazine
Contact
Langue
MyWeisang

Paramètres du compte.

Topic

Copy a matrix into excel

Page d'accueil ' Communauté ' Automation et VBA ' Copier une matrice dans excel

Voir les messages de 3 - 1 à 3 (sur un total de 3)
  • Auteur
    Messages
  • #35218
    Peter Seitz
    Participant

    Hello,

    i have a 29×29 dimensional matrix which I want to include in an excel sheet.
    For example a matrix build up within in a formula like this:

    [code]Dim Output = ? # 29 # 29 // Dim a 29×29 matrix
    Output[0,28][0,28] = -1 // Fill all cells with -1

    [ Output][/code]

    I want this Output to be copied into an excel sheet. I used following code:

    [code]
    Option Explicit

    Const sExcelSheet As String = “P:TestFile.xlsx”

    Sub DataIntoExcel()

    ‘access data from FlexPro
    Dim oFolder As Folder
    Set oFolder = ActiveDatabase.RootFolder
    Dim matrix
    Set matrix = oFolder.Object(“Formel”, fpObjectTypeFormula).Value

    ‘ open Excel sheet
    Dim oExcel As Object
    Set oExcel = CreateObject(“Excel.Application”)

    With oExcel
    .Visible = True
    .Workbooks.Open Filename:=sExcelSheet, ReadOnly:=False
    With .Workbooks(1)
    Dim oSheet As Object
    Set oSheet = .Worksheets(1)

    oSheet.Range(“C3:AE31”) = matrix
    End With
    End With
    Set oExcel = Nothing
    End Sub[/code]

    The matrix is supposed to be placed starting at cell C3 or placed in the area from C3 to AE31. I keep getting runtime errors though.

    Can someone tell me what i did wrong. Thanks in advance.

    kind regards,
    Peter

    #35220
    Peter Seitz
    Participant

    Hello,

    i have a 29×29 dimensional matrix which I want to include in an excel sheet.
    For example a matrix build up within in a formula like this:

    [code]Dim Output = ? # 29 # 29 // Dim a 29×29 matrix
    Output[0,28][0,28] = -1 // Fill all cells with -1

    [ Output][/code]

    I want this Output to be copied into an excel sheet. I used following code:

    [code]
    Option Explicit

    Const sExcelSheet As String = “P:TestFile.xlsx”

    Sub DataIntoExcel()

    ‘access data from FlexPro
    Dim oFolder As Folder
    Set oFolder = ActiveDatabase.RootFolder
    Dim matrix
    Set matrix = oFolder.Object(“Formel”, fpObjectTypeFormula).Value

    ‘ open Excel sheet
    Dim oExcel As Object
    Set oExcel = CreateObject(“Excel.Application”)

    With oExcel
    .Visible = True
    .Workbooks.Open Filename:=sExcelSheet, ReadOnly:=False
    With .Workbooks(1)
    Dim oSheet As Object
    Set oSheet = .Worksheets(1)

    oSheet.Range(“C3:AE31”) = matrix
    End With
    End With
    Set oExcel = Nothing
    End Sub[/code]

    The matrix is supposed to be placed starting at cell C3 or placed in the area from C3 to AE31. I keep getting runtime errors though.

    Can someone tell me what i did wrong. Thanks in advance.

    kind regards,
    Peter

    #35219
    Bernhard Kantz
    Participant

    Your code should work if you assign the value of the formula evaluation instead of the value object itself to your matrix variable.

    [code]
    Dim fml As Formula
    Set fml = ActiveDatabase.RootFolder(“Formel”, fpObjectTypeFormula)
    fml.Update
    Dim matrix
    matrix = fml.Value
    [/code]

    Note the update of the formula before using its value.

    Hint: To exchange rows and columns use Application.WorksheetFunction.Transpose(matrix) in the assignment to the range.

Voir les messages de 3 - 1 à 3 (sur un total de 3)
  • Vous devez être connecté pour répondre à ce sujet.