2017-10-11 38 views
-1

我一直在嘗試編碼&,如字符& chr(38),但它保留底層的單詞。任何解決方案?如何從VBA打印和從Excel到Excel

Private Sub createMenu() 
'define the variables 
    Dim mnuDownload1 As Menu 

    'create the menue bar 
    With MenuBars(xlWorksheet) 
     .Reset 
     .Menus.Add "Import", 1 

     'define the menue bar 
     Set mnuDownload1 = MenuBars(xlWorksheet).Menus("Import") 

     'for each defined menu bar at the sub item , the first "" is the name of the item. The second "" is the macro name 
     With mnuDownload1.MenuItems 
     .AddMenu Caption:="P&S" 
     .Item("P&S").MenuItems.Add "Exclude P" & Chr(38) & "S", "changes" 
     End With 
End With 
End Sub 
+0

這是所有的代碼是完整的?正如你寫的那樣,或者用chr(38)會在msgbox中顯示「&」 – QHarr

+1

你的代碼對我來說工作得很好。它顯示&只是你想要的。 – braX

+0

對不起,我上面更新 – Lowpar

回答

1

事實上正常的行爲,一週時間Chr(38)伏於下一個字符時忙中menuitems。 A msgbox將顯示正常的&符號。如果要將&符號用作菜單項中的字符,請使用"Exclude P" & Chr(38) & Chr(38) & "S""Exclude P&&S"中的字符兩次。