dim app as Microsoft.Office.Interop.Excel.ApplicationClass;
dim workbook as Microsoft.office.Interop.Excel.Workbookclass;
app =new Microsoft.Office.Interop.Excel.Application;
app.Visible = true;
workbook =app.Workbooks.Open(InfoInTouchAppDir( )+"\test.xlsm");
app.Run("test.xlsm!test1","testarg");
workbook.Activate();
dim intptr as System.IntPtr;
intptr = app.Hwnd;
LogMessage(app.Hwnd);
LogMessage(intptr);
Vanara.PInvoke.User32.SetForegroundwindow(intptr);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Excel = Microsoft.Office.Interop.Excel;
namespace ConsoleApp9
{
internal class Program
{
static void Main(string[] args)
{
// 创建 Excel 应用程序实例
Excel.Application excelApp = new Excel.Application();
excelApp.Visible = true;
try
{
// 打开包含宏的 Excel 文件
Excel.Workbook workbook = excelApp.Workbooks.Open(@"C:\Users\Administrator\Documents\test.xlsm");
try
{
// 运行指定的宏
excelApp.Run("'test.xlsm'!test1","test");
}
catch (Exception ex)
{
Console.WriteLine("Error running macro: " + ex.Message);
}
finally
{
Console.ReadKey();
// 保存工作簿并关闭
workbook.Save();
workbook.Close();
}
}
catch (Exception ex)
{
Console.WriteLine("Error opening workbook: " + ex.Message);
}
finally
{
// 退出 Excel 应用程序
excelApp.Quit();
// 释放 COM 对象
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
}
Console.ReadKey();
}
}
}