我試圖訪問Access資料庫(accdb)中的宏。
我試著用:
我試著用:
using Microsoft.Office.Interop.Access.Dao;
...
DBEngine dbe = new DBEngine()。
資料庫ac = dbe.OpenDatabase(fileName)。
我發現一個container["Scripts"]有一個document["Macro1"],它是我的目標。我正在努力訪問該檔案的內容。我還質疑Microsoft.Office.Interop.Access.Dao是否是我所要實作的目標的最佳參考。
查看宏和模塊內容的最佳方法是什么?
uj5u.com熱心網友回復:
你可以跳過DAO部分,它在這種情況下不需要。宏是針對專案的,所以為了得到它們,你需要在你的專案中回圈。在我的例子中,我只有一個專案。
using System;
using System.Collections.Generic;
using System.Text.Document; using System.Text.Document
使用System.Threading.Tasks;
namespace Sandbox48
{
public class Program {
{
public static void Main(string[] args)
{
Microsoft.Office.Interop.Access.Application oAccess = null;
string savePath = @"C:macros"/span>;
oAccess = new Microsoft.Office.Interop.Access.Application()。
//在獨占模式下打開一個資料庫:。
oAccess.OpenCurrentDatabase(
@"", //filepath.
true //Exclusive
);
var allMacros = oAccess.CurrentProject.AllMacros;
foreach(var macro in allMacros)
{
var fullMacro = (AccessObject)macro;
Console.WriteLine(fullMacro.Name)。
oAccess.SaveAsText(AcObjectType.acMacro, fullMacro.FullName, $"{savePath}{ fullMacro.Name}.txt"/span>)。
}
Console.Read()。
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/314459.html
標籤:
