0

Problem:
While copying a cell which contains 'script' from Excel into another program, double-quotation marks ("") are added automatically instead of single-quotation mark only (").

Also, at the beginning and end of scripts, a " is automatically added.

Here is my script, and the emphasized quotes are the extraneous ones:

"// script to change budget by day of week // Jon Gritton 2016

// user vars var BUDG_NAME = " "Shared budget S104 (CX - High)" "; var B_MON = 500000 ; var B_TUE = 500000 ; var B_WED = 500000 ; var B_THU = 500000 ; var B_FRI = 500000 ; var B_SAT = 500000 ; var B_SUN = 500000 ;

function main() { setBudget(getBudgetToday()); }

function getBudgetToday() { var budgArray = [B_SUN,B_MON,B_TUE,B_WED,B_THU,B_FRI,B_SAT]; var d = new Date(Utilities.formatDate(new Date(), >AdWordsApp.currentAccount().getTimeZone(), " "MMM dd,yyyy HH:mm:ss" ")); var today = d.getDay(); return budgArray[today]; }

function setBudget(budgetToday) { Logger.log(" "Budget for today is: " " + budgetToday); var budgetIter = AdWordsApp.budgets() .withCondition(" "BudgetName = '" " + BUDG_NAME + " " ' " ") .get() while (budgetIter.hasNext()) { var thisBudget = budgetIter.next(); thisBudget.setAmount(budgetToday); } }"

Details:
I'm using Excel 2013 on Windows 10.

I've read on other thread that we can solve this by using this macro

Sub CopyCellContents()
  'create a reference in the VBE to Microsft Forms 2.0 Lib
  Dim objData As New DataObject
  Dim strTemp As String
  strTemp = ActiveCell.Value
  objData.SetText (strTemp)
  objData.PutInClipboard
End Sub

but apparently this macro is only compatible with Excel 2007, and not Excel 2013:

"Compile error: User-defined type not defined"

The only work-around is to copy the cell (that contains the script) into Word 2013 and copy the text through blocking the formula bar. But I need to just copy the cell to the new program.

How can I keep these double-quotes from showing up when copying to another program? In other words, can I get rid of these double quotation marks from being automatically added when the cell is copied to clipboard?

robinCTS
  • 4,327
  • 4
  • 20
  • 29
freakyholic
  • 75
  • 1
  • 6
  • Multiline text copied from Excel automatically includes quotation marks. See this similar question: https://superuser.com/questions/324271/how-to-copy-multi-line-text-from-excel-without-quotes – davidmneedham Jun 20 '18 at 18:25
  • @davidmneedham That's probably where freakyholic got the macro from. [This comment](//superuser.com/q/324271/#comment1269458_324271) on the question leads to [this answer](//stackoverflow.com/a/24913557/976210) to another question where the very same macro resides. – robinCTS Jun 20 '18 at 18:55
  • @robinCTS , you're probably right. Is this a duplicate question? – davidmneedham Jun 20 '18 at 19:01
  • @davidmneedham Given that the problem is not so much that the quotes need removing, but that the solutions found in that other question aren't working (which my answer solves), I would say no. – robinCTS Jun 20 '18 at 19:06

1 Answers1

1

Actually, that macro is compatible with Excel 2013. What you need to do is add a reference to the Microsoft Forms 2.0 Object Library, as explained in the comment on the second line of the code.

In the VBE, go to ToolsReferences…, scroll down until you find the Forms reference (it will be under "M") and tick the checkbox:

Add References Screenshot

The macro should work now.

robinCTS
  • 4,327
  • 4
  • 20
  • 29