VBA saving workbook creates null bytes?

joshman108

Active Member
Joined
Jul 6, 2016
Messages
310
This may be a python question, not sure. I am using the following vba code to create and save a new workbook with information from the first.

Rich (BB code):
Range("u3", Range("u3").End(xlToLeft).End(xlDown)).Copy                      ' copy some data from open workbook                      
Set dealbook = Workbooks.Add                                               'set new workbook
dealbook.Worksheets("sheet1").Cells.NumberFormat = "@"                         'format new workbook as text
dealbook.Worksheets("sheet1").Range("a1").PasteSpecial Paste:=xlPasteValues   'paste as values into new workbook
Do
       dName = Application.GetSaveAsFilename  'save the file
       Loop Until dName <> False
       dealbook.SaveAs Filename:=dName

That creates a prompt for the user to save the file, select the file type and file name. When the user hits "save" it closes the prompt and continue with macro. Everything seems to be fine until I try uploading the file into our database via a python script. The following error message appears:


Here is the error given by python
Rich (BB code):
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}span.s1 {font-variant-ligatures: no-common-ligatures}</style>Traceback (most recent call last):
  File "./log.py", line 37, in <module>
    rows = list(reader)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/csv.py", line 107, in next
    self.fieldnames
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/csv.py", line 90, in fieldnames
    self._fieldnames = self.reader.next()
_csv.Error: line contains NULL byte

Also, when I then go to open said file on my computer which contains NULL bytes, excel gives me this message:
Rich (BB code):
The file format and extension of 'rev backfills.csv' don't match. The file could be corrupted or unsafe. 
Unless you trust its source, don't open it. Do you want to open it anyway? 


Any ideas what's happening here? I am struggling to find much online.

Version 15.39 for mac.
</module>
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
specifically, when I save the file as prompted by the vba macro, I am saving as "windows comma separated" as opposed to "comma separated values" and "MS DOS separated values" which are both options as well. That is the format we need for a successful upload via our scripts, or so i was told
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top