AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1569074
Accepted
Lluser
Lluser
Asked: 2020-07-17 00:39:52 +0800 CST2020-07-17 00:39:52 +0800 CST 2020-07-17 00:39:52 +0800 CST

如何将 VBA 代码格式化为 80 列?

  • 772

我有一些 VBA 代码,其中行很长并且想将其发送到某个地方,其中(不是 100% 严格)限制 80 个字符在线。

_VBA 允许通过在“ ”之前放置“”来创建中断代码行enter。(显然,这在字符串中不起作用,必须将其拆分为子字符串并用“ &”连接。如下所示。)

是否有一些工具可以自动将“换行符”添加到代码中?
或者也许是正则表达式?

我试图搜索,但没有有效的结果。

原始代码:

'Some looooooong comment Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut a volutpat dolor. In risus odio, pharetra a arcu in, efficitur ornare lectus. Maecenas non aliquet leo. Praesent luctus blandit magna, et sagittis ex porta et.
MsgBox("Some text in MsgBox. Donec vulputate eros ac nulla hendrerit auctor. In hac habitasse platea dictumst. Proin fermentum augue elit, eget consequat massa mattis et. Integer semper imperdiet diam sit amet malesuada.", 64, "Title of MsgBox")
'Another comment now with link to doc. https://example.com/?bs64=SWYgeW91IGFyZSBzbWFydCBlbm91Z2ggdG8gZGVjb2RlLCB5b3UgbXVzdCBkZWZpbml0ZWx5IHdhdGNoIHRoaXM6IGh0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9b0hnNVNKWVJIQTA=

想要的代码:

'Some looooooong comment Lorem ipsum dolor sit amet, consectetur adipiscing
'elit. Ut a volutpat dolor. In risus odio, pharetra a arcu in, efficitur
'ornare lectus. Maecenas non aliquet leo. Praesent luctus blandit magna, et
'sagittis ex porta et.
MsgBox("Some text in MsgBox. Donec vulputate eros ac nulla hendrerit auctor." _
 & "In hac habitasse platea dictumst. Proin fermentum augue elit, eget " _ 
 & "consequat massa mattis et. Integer semper imperdiet diam sit amet" _
 & " malesuada.", 64, "Title of MsgBox")
'Another comment now with link to doc.
'https://example.com/?bs64=SWYgeW91IGFyZSBzbWFydCBlbm91Z2ggdG8gZGVjb2RlLCB5b3UgbXVzdCBkZWZpbml0ZWx5IHdhdGNoIHRoaXM6IGh0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9b0hnNVNKWVJIQTA=

谢谢。

PS:我正在使用记事本++

regex notepad++
  • 1 1 个回答
  • 94 Views

1 个回答

  • Voted
  1. Best Answer
    JvdV
    2020-07-17T01:23:31+08:002020-07-17T01:23:31+08:00

    也许您可以使用两个正则表达式搜索和替换功能?一个只处理带有注释的行,另一个将处理带有 MsgBox 的行。这将使常规 VBA 不受影响。第一种模式可能是:

    ^[^'].*(*SKIP)(*F)|(?:(?:.{1,70}|.{71,140}|.{141,210}|.{211,280})|\G(?!^))\S+\K\h(?=.{25,}$)
    

    替换为 \n',查看在线演示


    第二个:

    ^(?!MsgBox\().*(*SKIP)(*F)|(?:(?:.{1,70}|.{71,140}|.{141,210}|.{211,280})|\G(?!^))\S+\K\h(?=.{25,}$)
    

    替换为 " _\n & ",查看在线演示


    模式原理的细分:

    • ^- 起跑线锚。
    • [^']- 匹配除文字单引号外的任何字符。
    • .*- 匹配除换行符以外的任何字符零次或多次。
    • (*SKIP)(*F)- 跳过/失败组合以消耗匹配的模式,但稍后将其否定。
    • |- 交替/或。
    • (?:- 打开第一个非捕获组。
      • (?:- 打开第二个非捕获组。
        • .{1,70}|.{71,140}|.{141,210}|.{211,280}- 交替匹配除换行符以外的任何字符 x 次。如果您的字符串值更长,您可以添加更多。
        • )- 关闭嵌套的第二个非捕获组。
      • |- 交替/或。
      • \G(?!^)- 在上一个匹配结束时断言位置并带有负前瞻,以防止字符串位置的开始。
      • )- 关闭第一个非捕获组。
    • \S+- 匹配至少 1 个非空白字符。
    • \K- 重置之前报告的比赛的起点。
    • \h- 匹配水平空白字符。
    • (?=.{25,}$)- 正向前瞻以确保在结束字符串 ancor 之前至少还有 25 个字符(以防止出现小的结尾部分)。

    而上述模式适用于作为注释的行。与第二个模式的唯一区别是它使用负前瞻来确保该行不以文字'MsgBox(')开头。


    在此处输入图像描述

    我的最终结果:

    'Some looooooong comment Lorem ipsum dolor sit amet, consectetur adipiscing 
    'elit. Ut a volutpat dolor. In risus odio, pharetra a arcu in, efficitur 
    'ornare lectus. Maecenas non aliquet leo. Praesent luctus blandit 
    'magna, et sagittis ex porta et.
    MsgBox("Some text in MsgBox. Donec vulputate eros ac nulla hendrerit auctor. " _
     & "In hac habitasse platea dictumst. Proin fermentum augue elit, eget consequat " _
     & "massa mattis et. Integer semper imperdiet diam sit amet " _
     & "malesuada.", 64, "Title of MsgBox")
    'Another comment now with link to doc. 
    'https://example.com/?bs64=SWYgeW91IGFyZSBzbWFydCBlbm91Z2ggdG8gZGVjb2RlLCB5b3UgbXVzdCBkZWZpbml0ZWx5IHdhdGNoIHRoaXM6IGh0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9b0hnNVNKWVJIQTA=
    
    • 1

相关问题

  • Notepad++ 删除直到冒号替换所有行

  • OneDrive 有 .gitignore 吗?

  • NotePad++ 用户定义语言不显示条件语句

  • 如果一个字符串出现在正则表达式中的另一个字符串之前,如何停止搜索

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve