2016-03-04 78 views
-1

我試圖讓Excel中創建使用VBA(我第一次)的XML文件,所以我設法創建一個代碼,但我不斷收到有太多的連接行減少行繼續在Excel

消息

這是我的代碼

Sub testXLStoXML() 
sTemplateXML = _ 
    "<?xml version='1.0'?>" + vbNewLine + _ 
"<offers>" + vbNewLine + _ 
" <offer>" + vbNewLine + _ 
"  <offer_identifier>" + vbNewLine + _ 
"  </offer_identifier>" + vbNewLine + _ 
"  <offer_title>" + vbNewLine + _ 
"  </offer_title>" + vbNewLine + _ 
"  <offer_description>" + vbNewLine + _ 
"  </offer_description>" + vbNewLine + _ 
"  <offer_featured_image>" + vbNewLine + _ 
"  </offer_featured_image>" + vbNewLine + _ 
"  <offer_cat>" + vbNewLine + _ 
"  </offer_cat>" + vbNewLine + _ 
"  <offer_location>" + vbNewLine + _ 
"  </offer_location>" + vbNewLine + _ 
"  <offer_tags>" + vbNewLine + _ 
"  </offer_tags>" + vbNewLine + _ 
"  <offer_type>" + vbNewLine + _ 
"  </offer_type>" + vbNewLine + _ 
"  <offer_start>" + vbNewLine + _ 
"  </offer_start>" + vbNewLine + _ 
"  <offer_expire>" + vbNewLine + _ 
"  </offer_expire>" + vbNewLine + _ 
"  <offer_store>" + vbNewLine + _ 
"  </offer_store>" + vbNewLine + _ 
"   <!-- store -->" + vbNewLine + _ 
"   <store_title>" + vbNewLine + _ 
"   </store_title>" + vbNewLine + _ 
"   <store_letter>" + vbNewLine + _ 
"   </store_letter>" + vbNewLine + _ 
"   <store_description>" + vbNewLine + _ 
"   </store_description>" + vbNewLine + _ 
    "   <store_logo>" + vbNewLine + _ 
"   </store_logo>" + vbNewLine + _ 
    "   <store_link>" + vbNewLine + _ 
"   </store_link>" + vbNewLine + _ 
"   <store_facebook>" + vbNewLine + _ 
"   </store_facebook>" + vbNewLine + _ 
"   <store_twitter>" + vbNewLine + _ 
"   </store_twitter>" + vbNewLine + _ 
"   <store_google>" + vbNewLine + _ 
"   </store_google>" + vbNewLine + _ 
"   <!-- store -->" + vbNewLine + _ 
"  <!-- DEAL RELATED -->" + vbNewLine + _ 
"  <deal_items>" + vbNewLine + _ 
"  </deal_items>" + vbNewLine + _ 
"  <deal_item_vouchers>" + vbNewLine + _ 
"  </deal_item_vouchers>" + vbNewLine + _ 
"  <deal_price>" + vbNewLine + _ 
"  </deal_price>" + vbNewLine + _ 
"  <deal_sale_price>" + vbNewLine + _ 
"  </deal_sale_price>" + vbNewLine + _ 
"  <deal_discount>" + vbNewLine + _ 
"  </deal_discount>" + vbNewLine + _ 
"  <deal_voucher_expire>" + vbNewLine + _ 
"  </deal_voucher_expire>" + vbNewLine + _ 
"  <deal_in_short>" + vbNewLine + _ 
"  </deal_in_short>" + vbNewLine + _ 
"  <deal_type>" + vbNewLine + _ 
"  </deal_type>" + vbNewLine + _ 
"  <deal_link>" + vbNewLine + _ 
"  </deal_link>" + vbNewLine + _ 
" </offer>" + vbNewLine + _ 
"</offers>" + vbNewLine + 

有沒有辦法繞過限制或使這項工作?

回答

0

根據Microsoft的說法,「您可以使用續行字符加入的行數有限制,該錯誤的原因和解決方案如下: 您的代碼中有超過25行的物理行行連續續行字符,或者在一行中連續超過24個連續字符,使一些構成行在物理上更長一些,以減少所需續行字符的數量,或將構造分解爲多個語句。

該行的延續僅僅是爲了方便閱讀代碼,並且必須在每個標籤之後擁有現在的樣子

+0

謝謝。你知道如何使線條更長嗎? –

+1

你爲什麼要將內容分割成多行?例如,您可以將開始標籤和結束標籤放在同一行上,也可以將多行放入較長的行中。 –

+0

「+」vbNewLine +「」+ vbNewLine + – Fred