+ Reply to Thread
Results 1 to 9 of 9

Workbooks.Open macro changes the cell format

  1. #1
    Registered User
    Join Date
    02-05-2021
    Location
    Helsinki, Finland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    12

    Exclamation Workbooks.Open macro changes the cell format

    I have a an issue... Opening a .xls-file manually, the number formats in the file are with dots such as 1.200 --> As they should.

    While opening the same file through a Workbooks.Open macro, it opens the file with the format changed to commas, in this case 1,2 .

    My goal is to get all the numbers in the file with over 999 to be in "0"-format , such as 1200 in this case.

    This drives me crazy. I feel this should be a simple thing to bypass, but I haven't been able to figure this out.

    Any help and workaround & explanation would be much appreciated.

    I've added an example file how it opens while opening it manually (with dots).



    The system we use can only save the data in .xls or .txt .

    I've tried to save the files to .xlsx and .xlsm before opening them through VBA, but still the Workbooks.Open macro changes the cell format when it opens the file.

    I attached the file just to give the idea of the original file and format and the goal. I hoped someone could find a macro or solution that helps. This error occurs on opening the file, so there is really no written code to evaluate in this case.
    Attached Files Attached Files
    Last edited by ETalvitie; 02-08-2021 at 05:28 AM.

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: Workbooks.Open macro changes the cell format

    It seems to me that the file you attached isn't a 'true' Excel file but a .txt renamed .xls .
    Anyway since your file doesn't contain macro it's impossibile to evalutate what happens with your Workbook.Open.
    Last edited by rollis13; 02-08-2021 at 05:46 AM.

  3. #3
    Registered User
    Join Date
    02-05-2021
    Location
    Helsinki, Finland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    12

    Re: Workbooks.Open macro changes the cell format

    For opening I just use a basic Workbooks.Open - command from the directory where the file is.

    Here's the macro where I think the issues lies:

    I want to open the .txt-file then do the correct format on the number cells and save it as .xlsx-format. After this macro, the dots are (back to/again/still) in commas.


    Please Login or Register  to view this content.


    But the problem here is too, that when the macro opens the workbook, dots are in commas. When opening manually, dots are dots. Why is the macro doing this?
    Last edited by davesexcel; 02-08-2021 at 08:00 AM.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Workbooks.Open macro changes the cell format

    Workbooks.Open has a Local parameter you should be using - add:

    Please Login or Register  to view this content.
    to your Open command.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Registered User
    Join Date
    02-05-2021
    Location
    Helsinki, Finland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    12

    Re: Workbooks.Open macro changes the cell format

    Quote Originally Posted by rorya View Post
    Workbooks.Open has a Local parameter you should be using - add:

    Please Login or Register  to view this content.
    to your Open command.

    This did the trick! Thank you so much Rory! You made my - not just the day - but the whole rest of the year.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Workbooks.Open macro changes the cell format

    Glad we could help.

  7. #7
    Registered User
    Join Date
    02-05-2021
    Location
    Helsinki, Finland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    12

    Re: Workbooks.Open macro changes the cell format

    Out of curiosity and to understand this a bit better, what does that Local-parameter do in fact?

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Workbooks.Open macro changes the cell format

    It tells Excel to open the file using your regional settings to interpret any data rather than the default US regional settings.

  9. #9
    Registered User
    Join Date
    02-05-2021
    Location
    Helsinki, Finland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    12

    Re: Workbooks.Open macro changes the cell format

    Quote Originally Posted by rorya View Post
    It tells Excel to open the file using your regional settings to interpret any data rather than the default US regional settings.
    Ok, makes sense, now when I think about it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Run Macro to all open workbooks.
    By Fcxx in forum Excel General
    Replies: 8
    Last Post: 03-26-2019, 06:43 AM
  2. [SOLVED] Workbooks.open number format wrong
    By Teddi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2019, 08:15 AM
  3. VBA - Open Multiple Workbooks, copy values into one workbook and put in array format
    By vba_beckie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2018, 11:33 AM
  4. Replies: 1
    Last Post: 03-31-2016, 02:06 AM
  5. Macro on two open workbooks?
    By Hambone70 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-11-2013, 01:53 PM
  6. Macro to Open Up Workbooks
    By hyattj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2013, 12:35 PM
  7. Why do workbooks open in READ ONLY format
    By Hook in forum Excel General
    Replies: 2
    Last Post: 05-10-2012, 01:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1