VBA スクリプトを呼び出す Excel シートに埋め込みボタンがあります。このスクリプトでは、現在のディレクトリを読み取り、解析し、それを使用して値を生成し、string[] 引数を外部の C# 実行可能ファイルに渡します。私はこれを何度も繰り返しましたが、実行可能ファイルを呼び出しますが、C# .exe の実行時に渡されるパラメーターが null (空) であるように見えます。この C# .exe を他のプログラムで使用して引数を渡すことはできますが、この VBA スクリプトは期待どおりに動作しません。また、C# .exe から範囲外の例外が発生しないため、正しいパラメーター数が渡されていることもわかっています。現在、これをトラブルシューティングするために、これらすべての引数を文字列に変換していますが、おそらく必要ありません。添付の VBA コード:
Sub ButtonSG1b7_Click()
Dim FileLocation
Dim ProgramName
Dim length
FileLocation = ActiveWorkbook.FullName
length = Len(FileLocation) - 5
ProgramName = Left(FileLocation, length)
ProgramName = Right(ProgramName, 10)
length = Len(FileLocation) - 15
FileLocation = Left(FileLocation, length)
length = Len(FileLocation) - 2
FileLocation = Right(FileLocation, length)
MsgBox "File Location : " & FileLocation & " Program Name: " & ProgramName
Dim str0 As String
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim str4 As String
Dim str5 As String
Dim str6 As String
str0 = "H:\StageGate\Administration\Scripts\GetLatestFileOpen.exe "
str1 = "H:"
str2 = FileLocation
str3 = "Common"
str4 = "\Market Feasibility "
str5 = ProgramName
str6 = ".xlsx"
MsgBox str0 & str1 & str2 & str3 & str4 & str5 & str6
Shell (str0 & str1 & str2 & str3 & str4 & str5 & str6)
End Sub
編集 (引数を取り、それをリストに変換し、リストを使用して文字列ファイルパスを提供し、EPDM ボルト内のフォルダーで最新を取得し、ファイルの更新されたローカル コピーを開く、Solidworks EPDM ライブラリを含む暫定的な C# コードを追加します。 .) :
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using EPDM.Interop.epdm;
class Program
{
static void Main(string[] args)
{
IEdmFolder5 ppoRetParentFolder;
List<string> filePath = new List<string>(args);
if (filePath.Any())
{
filePath.RemoveAt(0); //really need to just stop having the script call passing this argument.
}
if (Directory.Exists(@"C:\StageGate")) {
filePath.Insert(0,"C:");
}
else if (Directory.Exists(@"H:\StageGate"))
{
filePath.Insert(0,"H:");
}
else
{
MessageBox.Show("StageGate not found.");
}
string newFilePath = string.Join("", filePath.ToArray());
filePath.RemoveAt(5);
filePath.RemoveAt(4);
filePath.RemoveAt(3);
string folderPathstr = string.Join("", filePath.ToArray());
//MessageBox.Show(folderPathstr);
//Have to create vault object to work with BatchGet
EdmVault5 vault = new EdmVault5();
//Replace My_Vault with your vault name
vault.LoginAuto("StageGate", 0);
//Set the 2 here equal to how many folders you want to get (not counting subfolders)
EdmSelItem[] folderArray = new EdmSelItem[1];
IEdmBatchGet bg = (IEdmBatchGet)vault.CreateUtility(EdmUtility.EdmUtil_BatchGet);
//Create and array element for eachf older you want to get, replace folder locations with your folders
folderArray[0].mlDocID = 0;
folderArray[0].mlProjID = vault.GetFolderFromPath(folderPathstr).ID;
//fa[1].mlDocID = 0;
//fa[1].mlProjID = vault.GetFolderFromPath("C:\\My_Vault\\FolderPath").ID;
bg.AddSelection(vault, folderArray);
bg.CreateTree(0, (int)EdmGetCmdFlags.Egcf_IncludeAutoCacheFiles); //Egcf_IncludeAutoCacheFiles will get latest version of file
bg.GetFiles(0, null);
if (File.Exists(newFilePath))
{
Process process = Process.Start(newFilePath); //can't just open the file. Need to create new windows process to have the file open in the default application(process)
//File.Open(newPath, FileMode.Open);
}
else
{
MessageBox.Show("File not found.");
}