-2

I want to run a macro on CSV files that are sent to me using an xlwings script.

As such storing the macro in each new file would be a pain. Is there anyway to run the script from another workbook, or even just directly send the code to the CSV file?

Edit: I have tried doing it, however the macro documentation and the application documentation in xlwings seems to imply heavily that you can only call from the active workbook. Hence the question.

Community
  • 1
  • 1
Kelly
  • 7
  • 4
  • I need to do this via the Xlwings coding environment however, to automate it. – Kelly Mar 03 '17 at 16:12
  • A CSV file doesn't contain macros, it contains Comma-Separated Values - it's a plain text file with no formatting or anything, just the data. The downvotes would be because yes/no questions are utterly boring. Your answer is probably "yes, there's a way" - and if your *actual* question would be "mkay, so how do I do that?" then it's way *too broad* for this Q&A format. Did you read [ask] and [mcve]? – Mathieu Guindon Mar 03 '17 at 16:21
  • I'm aware of the former, hence using xlwings to call another file and grab the macro from there. I wouldn't call it broad, it should just be like two lines to show #how to define a macro as a variable #how to call that variable as a xlwings command I'm looking for like two lines. – Kelly Mar 03 '17 at 16:22
  • Possible duplicate of http://stackoverflow.com/q/30308455/1188513 – Mathieu Guindon Mar 03 '17 at 16:29
  • If you've tried, post what you tried and people will help you fix it. You may even get some up votes to offset the down votes. We can't help you fix what we can't see. – FreeMan Mar 03 '17 at 18:34
  • FYI: we're working on an addin version for the xlwings VBA module. – Felix Zumstein Mar 05 '17 at 18:35

1 Answers1

0

Yes.

You cannot, by definition, add macro code to a CSV file, so that option is out.

You would write your code in an XLSM. It would open your CSV, do whatever processing is necessary then save the output in whatever output format is necessary.

This should get you started:

Dim CSVFile as Workbook
Set CSVFile = Workbooks.Open("path\to\your\CSV\filename.csv")

As you run into specific issues when coding, open a new question (if searching first doesn't turn up an answer) to address that issue.

FreeMan
  • 5,660
  • 1
  • 27
  • 53
  • I think OP was looking for Python code, not VBA... but the question is off-topic / too broad anyway. – Mathieu Guindon Mar 03 '17 at 16:22
  • @Mat'sMug VBA was originally tagged, and it didn't specify in the question. I saw CSV and just assumed Excel since that's my little world these days. – FreeMan Mar 03 '17 at 18:22
  • @Mat'sMug See, I _knew_ an Excel/VBA answer was correct! It says Excel right there in the title of the question itself! – FreeMan Mar 03 '17 at 18:33