I've got a MACRO(.xlms) file and want to fetch the name of the multiple buttons given in it. So, from the below code I'm able to fetch the name of a single button MACRO but not able to fetch the name of multiple buttons MACRO. Apology If I've done any mistake in asking the question. i.e I'm new here.
input_path = str(input(r"Enter the input path: "))
import win32com.client as win32
import os
file_links = []
for root, dirs, files in os.walk(input_path):
for file in files:
full_file_name_link = os.path.join(input_path, file)
file_links.append(full_file_name_link)
for link in file_links:
excel = win32.gencache.EnsureDispatch("Excel.Application")
book = excel.Workbooks.Open(link)
is_completed = False
for i in book.VBProject.VBComponents:
num_lines = i.CodeModule.CountOfLines
for j in range(1, num_lines+1): #iterating num_lines
if 'Sub' in i.CodeModule.Lines(j, 1) and not 'End Sub' in i.CodeModule.Lines(j, 1):
module_name = i.CodeModule.Lines(j, 1).split(' ')[1].replace("()", "")
print(module_name)
excel.Application.Run(module_name) #Running the MACRO
book.Save()
book.Close()
is_completed = True
break
if is_completed:
break
excel.Application.Quit()
del excel
