アプリ版:「スタンプのみでお礼する」機能のリリースについて

お世話になっております。

vbsの以下の記述でexcelを開いています。

開くところまでは行くのですが、その後のsheet1のデータのクリアとUserForm1の表示がどうしてもできません。

申し訳ありませんが、どなたかおわかりの方、教えていただけないでしょうか。
宜しくお願いいたします。


Dim oApp
Dim objWshShell
Dim scriptPath

'Excelオブジェト作成
Set oApp = CreateObject("Excel.Application")
'WScript.Shellオブジェクト作成
Set objWshShell = CreateObject("WScript.Shell")

oApp.Visible = True '不可視にする
oApp.UserControl = True

'Excelファイルを開く
scriptPath = WScript.ScriptFullName
scriptPath = left(scriptPath,len(scriptPath)-len(WScript.ScriptName))
oApp.Workbooks.Open scriptPath & "共同資料.xlsm"

A 回答 (1件)

共同資料.xlsm に UserForm1 という名前のユーザーフォームが存在する。


共同資料.xlsm に標準モジュールを作成し、以下のコードを書いておく。

Public Sub ShowUserForm()
UserForm1.Show
End Sub

以下、VBScript のコード

Dim scriptPath
Dim bookPath

Dim fso ' パス文字列を操作するために FileSystemObject オブジェクトを使用
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
scriptPath = WScript.ScriptFullName
bookPath = fso.BuildPath(fso.GetParentFolderName(scriptPath), "共同資料.xlsm")


Dim oApp ' Excel Application オブジェクト
Dim targetBook ' 開いたブックの Workbook オブジェクト
Dim targetSheet ' sheet1 または 左から 1番目のシート
Set oApp = WScript.CreateObject("Excel.Application")
oApp.Visible = True
oApp.UserControl = True

Set targetBook = oApp.Workbooks.Open(bookPath)
Set targetSheet = targetBook.Worksheets("sheet1")
'Set targetSheet = targetBook.Worksheets(1) ' 左から 1番目ならこのコードでも可能


' どこの値/数式をクリアするのかは適宜変更
targetSheet.Range("A5").ClearContents

' 共同資料.xlsm の標準モジュールに書いた ShowUserForm プロシージャを実行
oApp.Run "共同資料.xlsm!ShowUserForm"
    • good
    • 0
この回答へのお礼

大変助かりました。
どうもありがとうございました。

お礼日時:2014/12/09 09:52

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!