热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用VB脚本运行MicrosoftOfficeVBA宏-RunningMicrosoftOfficeVBAmacrowithVBscript

IamworkingonaprojectaimedatshowinghowtorunamacroinMicrosoftOfficeusinganexternal

I am working on a project aimed at showing how to run a macro in Microsoft Office using an external Vbscript file. I have tried severally and failed at it also found a couple of posts here, all leaned towards Excel than Office. Having difficulties getting those examples to work on Office.

我正在开展一个项目,旨在展示如何使用外部Vbscript文件在Microsoft Office中运行宏。我已经尝试了几次并且失败了,它也发现了几个帖子,都倾向于Excel而不是Office。难以将这些示例用于Office。

1 个解决方案

#1


This applies to Excel - but the steps and procedures are identical in Word. I would search and replace Word for Excel but the code samples wouldn't make sense.

这适用于Excel - 但步骤和过程在Word中是相同的。我会搜索并替换Word for Excel,但代码示例没有意义。

Record the steps in excel macro recorder. You have to rewrite it a bit because it uses a type of syntax that vbs doesn't.

在excel宏录制器中记录步骤。你必须重写它,因为它使用了一种vbs没有的语法。

This applies (I don't have a medium9) xlRangeAutoFormatAccounting4 in vba.

这适用于(我没有medium9)xlRangeAutoFormatAccounting4在vba中。

Selection.AutoFormat Format:=xlRangeAutoFormatAccounting4, Number:=True, _
    Font:=True, Alignment:=True, Border:=True, Pattern:=True, Width:=True

So first look up constants in vba's object browser. xlRangeAutoFormatAccounting4 = 17

所以首先在vba的对象浏览器中查找常量。 xlRangeAutoFormatAccounting4 = 17

Then look the function up in object browser and look at the bottom for the function definition,.

然后在对象浏览器中查看该函数,并查看函数定义的底部。

Function AutoFormat([Format As XlRangeAutoFormat = xlRangeAutoFormatClassic1], [Number], [Font], [Alignment], [Border], [Pattern], [Width])

So the vba becomes in vbs (and vbs works in vba) (and as you can see you can work out the correct way without needing to look the function up usually)

所以vba变成了vbs(和vbs在vba中工作)(正如你所看到的,你可以通过正确的方式计算出来,而不需要通常查看函数)

Selection.AutoFormat 17, True, True, True,True, True, True

So your code becomes

所以你的代码变成了

objXLWs.Range("A3").CurrentRegion.Select.AutoFormat 17, True, True, True,True, True, True

You are using Excel and you can record it in Excel and have Excel write your code.

您正在使用Excel,您可以将其记录在Excel中并让Excel编写您的代码。

Alt + T, M, R

Alt + T,M,R

then Home key then Up Arrow. Stop recording.

然后是Home键然后向上箭头。停止录音。

Look what Excel wrote

看看Excel写的是什么

Selection.End(xlUp).Select

or if you had of recorded Go To dialog

或者如果您有录制的“转到”对话框

Application.Goto Reference:="R1C1"

or if you had of recorded Ctrl + Home

或者如果您有录制的Ctrl + Home

Range("A1").Select

推荐阅读
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 1.如何在运行状态查看源代码?查看函数的源代码,我们通常会使用IDE来完成。比如在PyCharm中,你可以Ctrl+鼠标点击进入函数的源代码。那如果没有IDE呢?当我们想使用一个函 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • 本文基于刘洪波老师的《英文词根词缀精讲》,深入探讨了多个重要词根词缀的起源及其相关词汇,帮助读者更好地理解和记忆英语单词。 ... [详细]
  • 本章将深入探讨移动 UI 设计的核心原则,帮助开发者构建简洁、高效且用户友好的界面。通过学习设计规则和用户体验优化技巧,您将能够创建出既美观又实用的移动应用。 ... [详细]
  • 技术分享:从动态网站提取站点密钥的解决方案
    本文探讨了如何从动态网站中提取站点密钥,特别是针对验证码(reCAPTCHA)的处理方法。通过结合Selenium和requests库,提供了详细的代码示例和优化建议。 ... [详细]
  • 本文详细介绍了如何解决Uploadify插件在Internet Explorer(IE)9和10版本中遇到的点击失效及JQuery运行时错误问题。通过修改相关JavaScript代码,确保上传功能在不同浏览器环境中的一致性和稳定性。 ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 扫描线三巨头 hdu1928hdu 1255  hdu 1542 [POJ 1151]
    学习链接:http:blog.csdn.netlwt36articledetails48908031学习扫描线主要学习的是一种扫描的思想,后期可以求解很 ... [详细]
  • 利用存储过程构建年度日历表的详细指南
    本文将介绍如何使用SQL存储过程创建一个完整的年度日历表。通过实例演示,帮助读者掌握存储过程的应用技巧,并提供详细的代码解析和执行步骤。 ... [详细]
  • 本文讨论了如何根据特定条件动态显示或隐藏文件上传控件中的默认文本(如“未选择文件”)。通过结合CSS和JavaScript,可以实现更灵活的用户界面。 ... [详细]
  • 尽管使用TensorFlow和PyTorch等成熟框架可以显著降低实现递归神经网络(RNN)的门槛,但对于初学者来说,理解其底层原理至关重要。本文将引导您使用NumPy从头构建一个用于自然语言处理(NLP)的RNN模型。 ... [详细]
  • 本文介绍了在Windows Server 2003环境下,使用XAMPP Lite 1.7.1和DotProject 2.1.3时遇到的日历和甘特图中文乱码问题的解决方案。通过修改相关文件和配置,可以有效解决这些问题。 ... [详细]
author-avatar
平凡书生518
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有