2013-04-10 71 views
1

我嘗試添加以下代碼在一組細胞的前一列在Excel 2011年如何HTML標籤EXCELL使用VBA

<div class="cpt_product_description "><div> 

我試圖用添加到單元格的開始這樣的:

Sub Add2Formula() 

' Add text 

For Each c In Selection 

c.Activate 

ActiveCell.FormulaR1C1 = "test - " & ActiveCell.Formula 

Next c 

End Sub 

---這工作,並添加 「測試 - 」 在細胞中的前 - 導致這些預期結果:

test - lknaslkndaslkdn 

當我嘗試在vba代碼中添加div html(其中「test - 」位於上面的代碼示例中)時,它會給我提供像「unexpected:exception」這樣的錯誤,並將文本紅色高亮顯示,好像存在格式問題vba編輯器....我是否缺少允許像<和空格這樣的字符的東西以及「等等?

任何幫助將不勝感激。

最後的結果應該是這樣的:

<div class="cpt_product_description "><div>lknaslkndaslkdn 

回答

1

用你的文字爲"<div class=""cpt_product_description ""><div>"

ActiveCell.FormulaR1C1 = "<div class=""cpt_product_description ""><div>" & ActiveCell.Formula 

加解釋

中指出:「開始或一條紋的末端ng vba。如果你需要一個「字符串中的唯一方法vba可以讓你這樣做,就是使用2例如」「。

+0

啊 - 完美! - 工作。感謝! – Neosonic 2013-04-10 18:41:09

+0

好奇 - 圍繞cpt_product_description的額外引號 - 需要因爲它沒有格式化空間的問題? – Neosonic 2013-04-10 18:43:29

+1

偉大的 - 完美的解釋 – Neosonic 2013-04-10 19:45:51