+ Reply to Thread
Results 1 to 5 of 5

Mac Excel VBA to save newly created workbook as CSV Cannot access read-only document

  1. #1
    Registered User
    Join Date
    06-14-2021
    Location
    USA
    MS-Off Ver
    Office 2019 (Mac)
    Posts
    2

    Mac Excel VBA to save newly created workbook as CSV Cannot access read-only document

    Hi, I am trying to copy a sheet from existing workbook (.xlsx) and save the sheet as new workbook (.csv):

    Set newcsv = Workbooks.Add

    ThisWorkbook.Sheets("sheet1").Copy before:=newcsv.Sheets(1)

    newcsv.SaveAs filename:="/users/XXX/desktop/"newfolder" & "/" & "newcsv" & ".csv", FileFormat:=xlCSV

    ThisWorkbook.Close savechanges:=False

    It runs into "Run-time error '1004': Cannot Access read-only document 'newcsv.csv.'

    I have tried to debug as below:

    Remove "fileformet:=xlcsv" and let it push through, file was successfully saved (however, saved csv would trigger security alert when opening)

    Since the code does not save the workbook because savechanges:=False, the workbook would close without save, that being said, the vba code remains same with FileFormat:=xlCSV.

    When I re-open the workbook and run macro, it pushes through and asks me whether to overwrite previous saved csv file and I can proceed to save it.

    The tricky part is that, it appears that all I have done above make the vba/macro just work fine, UNTIL next system reboot... YES reboot.

    When system is restarted, the workbook goes back to starting point, run into run-time error '1004'...

    Does anyone have any idea how to fix it?

    Thanks.

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent SAC
    Posts
    8,885

    Re: Mac Excel VBA to save newly created workbook as CSV Cannot access read-only document

    That can't be your actual code since there is an odd number of quotes in the SaveAs line.
    Rory

  3. #3
    Registered User
    Join Date
    06-14-2021
    Location
    USA
    MS-Off Ver
    Office 2019 (Mac)
    Posts
    2

    Re: Mac Excel VBA to save newly created workbook as CSV Cannot access read-only document

    I doesn't really matter on that way. My point is that after I remove FileFormat:=xlCSV the file pushes through, saving csv file that would trigger alert.

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent SAC
    Posts
    8,885

    Re: Mac Excel VBA to save newly created workbook as CSV Cannot access read-only document

    It does matter. It's hard to fix code if the code you post is not the actual code you are using.

  5. #5
    Registered User
    Join Date
    04-24-2023
    Location
    pakistan
    MS-Off Ver
    MS office 2016
    Posts
    1

    Re: Mac Excel VBA to save newly created workbook as CSV Cannot access read-only document

    myFolder = ThisWorkbook.Worksheets("Sample created Xero Upload temp").Range("F6")
    myFileName = InputBox("Wirte Name of the File without Extension", "Enter File Name", "Xero - " & ThisWorkbook.Worksheets("Sample created Xero Upload temp").Range("D2") & " " & ThisWorkbook.Worksheets("Sample created Xero Upload temp").Range("E2") & " " & ThisWorkbook.Worksheets("Sample created Xero Upload temp").Range("F2"))
    myFileName = myFileName & ".csv"

    Formula: copy to clipboard
    Please Login or Register  to view this content.



    mac-excel-vba-to-save-newly-created-workbook-as-csv-cannot-access-read-only-document
    Use This code only...

    Formula: copy to clipboard
    Please Login or Register  to view this content.

+ 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. Save and close newly created CSV workbook
    By marcosis in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-11-2021, 02:27 AM
  2. [SOLVED] How To save entire book Within a newly created Folder
    By TBM in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-23-2018, 10:33 AM
  3. Replies: 1
    Last Post: 09-20-2018, 04:32 AM
  4. [SOLVED] Email newly created line in excel workbook
    By klospros in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 11-21-2014, 11:48 AM
  5. Excel VBA Save a document created with word in both .doc and .html
    By Lavnpc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-18-2012, 01:01 PM
  6. How to copy to newly created sheet and save as PDF?
    By joanneb in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-30-2009, 04:05 PM
  7. i cannot open excel file error Cannot access read-only document me
    By Lenda. in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-14-2005, 03:06 PM

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