Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Access / VBA / Zugriff auf Excel-Funktionen

Empfohlene Antworten

Veröffentlicht

Hi, @all!

Ich brauche mal Hilfe:

In einer Access-Datenbank soll eine Zahl (0 < x < 4000) in die römische Schreibweise umgewandelt werden (Z.B.: 123 --> CXXIII)

Excel stellt eine entsprechende Funktion bereit: "Roman" ("Römisch" im Tabellenblatt.)

Access (anscheinend) nicht.

Mit folgendem Code kann ich auf die Excel-Funktion zugreifen, indem ich

- die in meine Funktion übergebene Zahl und die Umwandlungsformel in ein neues Tabellenblatt schreibe,

- den Wert in römischer Schreibweise auslese

- und diesen dann zurückgebe.

(Der entsprechende Verweis auf die "Excel-Object-Library" ist gesetzt.)

ABER:

Das muß doch auch einfacher gehen!?

Die Laufzeit ist unerträglich lang.

Und irgendwann wird sich ein User wundern, warum er "Mappe 4242" bekommt, wenn er manuell eine neue anlegt.

Wenn überhaupt eine neue angelegt werden kann (<-- Speicher nicht aufgeräumt?)

Hier erst einmal meine Lösung (ohne Test auf "Gültig(lngZahl)"):

Function fktRoman(lngZahl As Long) As String


Dim Excel2000 As Excel.Application

Dim blnExcelIsRunning As Boolean


    'Annahme: Excel ist geöffnet.

    '... = False, wenn Excel erst durch die

    ' Fehler-Routine gestartet wurde.

    ' Die entspr. Zuweisung erfolgt dort.

    blnExcelIsRunning = True


On Error GoTo Fehler

    Set Excel2000 = GetObject(, "Excel.Application")

On Error GoTo 0


    With Excel2000


        'Neue Mappe (<-- leer(!!))

        .Workbooks.Add

        'Zahl setzen, berechnen lassen, auslesen

        .Cells(1, 1) = lngZahl

        .Cells(1, 2) = "=Roman(A1)"

        fktRoman = .Cells(1, 2)

        '(Neue) Mappe schließen, nicht speichern

        .ActiveWorkbook.Close False


        'Wenn Excel nicht geöffnet war

        ' dann schließen

        If Not blnExcelIsRunning Then

            .Quit

        End If


    End With 'Excel2000


    Set Excel2000 = Nothing


Exit Function

Fehler:


    'Excel war nicht geöffnet

    Set Excel2000 = CreateObject("Excel.Application")

    blnExcelIsRunning = False


    Resume Next


End Function

vielleicht hilft dir das.

s'Amstel

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.