NauticalGent
Ignore List Poster Boy
- Local time
- Today, 03:34
- Joined
- Apr 27, 2015
- Messages
- 6,524
I tried to find this on AWF but was unable to find it, apologies if I am covering ground already covered. I learned yesterday that Trim in Excel works differently in Excel than Access:
Trim in Excel removes all spaces but one from a given string:
Trim in Access would only remove leading and trialing spaces:
So I wondered if I could tell Access to use the Excel version of Trim and after some research, here is what I came up with:
Anyway, I thought it was a good tool to have in the toolbox.
Trim in Excel removes all spaces but one from a given string:
Trim("1234 567 89")
returns "1234 567 89"Trim in Access would only remove leading and trialing spaces:
Trim("1234 567 89")
has no change.So I wondered if I could tell Access to use the Excel version of Trim and after some research, here is what I came up with:
Code:
Sub RunExcelFunctionFromAccess()
Dim excelApp As Object
Dim varResult As Variant
' Create a new instance of Excel Application
Set excelApp = CreateObject("Excel.Application")
' Run Excel function (e.g., TRIM)
varResult = excelApp.WorksheetFunction.Trim("1234 567 89")
Debug.Print "Result: " & varResult
' Clean up
excelApp.Quit
Set excelApp = Nothing
End Sub
Anyway, I thought it was a good tool to have in the toolbox.