我需要一種將變數從VBAC# app 傳遞的方法,該變數將是一個字串(路徑),它將用作 C# 方法(zip 和 unzip)中的引數。
示例:我VBA在 ms 訪問中的代碼:
Dim strSource,strDest,strPwd as string
strSource = CurrentProject.Path & "\AnyFolder"
strDest = CurrentProject.Path
strPwd = "BlaBla"
我的 C# 方法是這樣的:
void UnZipMe()
{
string MyZip = VBA.strSource;
string UnzipAt = VBA.strDest;
string MyZipPass = VBA.Pwd;
using (ZipFile archive = new ZipFile(MyZip))
{
archive.Password = MyZipPass;
archive.Encryption = EncryptionAlgorithm.PkzipWeak;
archive.StatusMessageTextWriter = Console.Out;
archive.ExtractAll(UnzipAt, ExtractExistingFileAction.Throw);
}
}
我可以將 VBA 變數值保存在表中,然后使用 C# 從 C# 獲取它,OLEDB但我正在嘗試這種方式,可以簡單地完成還是只是將值存盤在訪問表中?謝謝。
uj5u.com熱心網友回復:
我會將它們作為命令列引數傳遞。
(這是未經測驗的偽代碼。您可能需要將這些引數括在引號中,并可能轉義特殊字符)。
Shell("C:\your-program.EXE " & strSource & " " & strDest & " " & strPwd , 1)
您的 C# 程式可能類似于:
internal class Program
{
static void Main(string[] args)
{
string MyZip = args[0];
string UnzipAt = args[1];
string MyZipPass = args[2];
using (ZipFile archive = new ZipFile(MyZip))
{
archive.Password = MyZipPass;
archive.Encryption = EncryptionAlgorithm.PkzipWeak;
archive.StatusMessageTextWriter = Console.Out;
archive.ExtractAll(UnzipAt, ExtractExistingFileAction.Throw);
}
Console.WriteLine("Hello, World!");
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/497864.html
