से वीबीस्क्रिप्ट का उपयोग कर एक्सेल के बाहर से एक्सेल मैक्रो चलाएं मैं एक्सेल फ़ाइल के बाहर से एक्सेल मैक्रो चलाने की कोशिश कर रहा हूं। मैं वर्तमान में कमांड लाइन से चलने वाली ".vbs" फ़ाइल का उपयोग कर रहा हूं, लेकिन यह मुझे बताता है कि मैक्रो नहीं मिल सकता है। यहाँ स्क्रिप्ट मैंकमांड लाइन
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("test.xls")
objExcel.Application.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1, 1).Value = "Test value"
objExcel.Application.Run "Macro.TestMacro()"
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
WScript.Echo "Finished."
WScript.Quit
उपयोग करने के लिए कोशिश कर रहा हूँ और यहाँ मैक्रो मैं उपयोग करने के लिए कोशिश कर रहा हूँ है:
Sub TestMacro()
'first set a string which contains the path to the file you want to create.
'this example creates one and stores it in the root directory
MyFile = "C:\Users\username\Desktop\" & "TestResult.txt"
'set and open file for output
fnum = FreeFile()
Open MyFile For Output As fnum
'write project info and then a blank line. Note the comma is required
Write #fnum, "I wrote this"
Write #fnum,
'use Print when you want the string without quotation marks
Print #fnum, "I printed this"
Close #fnum
End Sub
मैं Is it possible to run a macro in Excel from external command? पर स्थित समाधान तक इस पाने की कोशिश की (और संशोधित बेशक) लेकिन यह काम नहीं लग रहा था। मैं त्रुटि प्राप्त कर रहा हूं 'माइक्रोसॉफ्ट ऑफिस एक्सेल: मैक्रो' मैक्रो। टेस्टमैक्रो 'नहीं मिला।
संपादित करें: एक्सेल 2003.
आप निकालने का प्रयास किया "मैक्रो।" और/या कोष्ठक और बस इसे इस objExcel.Aplication.Run "TestMacro" कहते हैं? – deusxmach1na
objExcel.Aplication.Run "test.xls! Macro.TestMacro" –
वे दोनों काम नहीं करते हैं :( – muttley91