2017-10-11 31 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"中的字符两次。