0

I want to automize some format work in one of my excel files. Therefore I used macros for a long time - now it's time to move to scripts I thought.

In the old world the cutsom style formating was done the following way:

    With Range(SB_TABLE_NAME + "[Menge Geliefert]")
        .NumberFormat = "## \Stk\."
    End With

With scripts its nearly the same

    cellColumn = sbOrderTable.getColumnByName("Menge Geliefert").getRange()
    cellColumn.setNumberFormatLocal("## \S\tk\.");

I also used the recording to be sure the number format is correct (!) but as soon as I do run the script I get the following error: Range setNumberFormatLocal: The argument is invalid, missing, or in incorrect format.

Do anyone has an idea why the recording is storing the user defined format but the running script failes with it? I also used the getNumberFormatLocal() to get the current formating - result: "## \S\tk." - so I get a little confused...

As described I wanted to set a range of cells (a column in a table) to a specifig fomrat.

1 Answer 1

0

The backslash in ## \Stk\. is an escape character. Pls change it to ! in OfficeScript.

cellColumn.setNumberFormatLocal("## !Stk!.");

Pls try below code, it creates same number format ## !Stk!. on my pc.

selectedSheet.getRange("a1").setNumberFormatLocal("## \\S\\tk\\.");
Sign up to request clarification or add additional context in comments.

6 Comments

Thx for the suggestion, but I get still the same error: The argument is invalid, missing, or in incorrect format.
Please check the cell format after running the VBA. Screenshot. I'm not sure if it is related to the Windows region settings. I've tested the OfficeScript without issure.
Hi taller Thanks a lot for Your suggestions! The formating in the cell is described the following way: ## \S\tk\.
I've update my answer. Pls try the 2nd code line.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.