如何通过选择列A直到数据存在来运行宏

发布于 2025-01-17 23:55:38 字数 933 浏览 1 评论 0原文

我正在尝试从 pythonwin32com.client 运行宏。当我手动尝试时,我的宏工作正常,因为它必须通过选择 A 列和行来运行,直到数据存在。 宏具有文本列功能和创建标题。

输入图片此处描述

结果 输入图片这里的描述

但是当我尝试从代码中它没有按预期工作。

import win32com.client as wincl

excel_app = wincl.DispatchEx("Excel.application")
excel_workbook = excel_app.Workbooks.Open(Filename=temp_macro_template_file_path, ReadOnly=1)
excel_app.Visible = True
excel_app.Columns('A')
excel_app.Application.Run("Macroname")
excel_workbook.Save()
excel_app.Application.Quit()

这就是我在这之后得到的。

输入图片此处描述

I am trying to run a macro from python and win32com.client. My macro is working fine when i am trying manually, Because it has to run by selecting column A and rows till data exists.
Macro has Text column functionality and creating headings as well.

enter image description here

results
enter image description here

But when i try from code it is not working as expected.

import win32com.client as wincl

excel_app = wincl.DispatchEx("Excel.application")
excel_workbook = excel_app.Workbooks.Open(Filename=temp_macro_template_file_path, ReadOnly=1)
excel_app.Visible = True
excel_app.Columns('A')
excel_app.Application.Run("Macroname")
excel_workbook.Save()
excel_app.Application.Quit()

This is what i am getting after this.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文