Hi,
We have a requirement where we need to show a message box when user clicks on the command button, for this since aspose doesn't support creating/handling macro's through code we have added the command button and handled the click event (Showing a Message Box) and saved it file as a .xlsm (Say Test.xlsm), we are using this as a template file. we are writing all the values to this template file and saving back with a different name(Say Test1.xlsm), the macro(button click event) is getting saved to the new file and the message box is being displayed when this button is clicked, it works fine till here.
In the requirement we also need to place this command button a particular location, and this location is dynamic, ie depending on the input this file gets, we need to place the button accordingly ie some times at range(20,1) and some times at range(40,3) and even at times hide this button as well.
While debugging we observed that when loading the template file Test1.xlsm, the command button is getting loaded as a picture, so when I am using the .Move or .MoveRange properties of the picture or shape it doesn't move to a different loaction/position, the command button looks like it is fixed at a location that is specified in the template. I am using the below code
Dim wbCopy As Workbook = New Workbook()
wbCopy.Open("C:\\Test1.xlsm", FileFormatType.Excel2007Xlsm)
'C:\\Test1.xlsm is having a Command Button with an handler for the click event, ie it shows a messagebox "hello" when clicked on the button and this button is placed on " A2 "cell
Dim wsCopy As Worksheet = wbCopy.Worksheets(0)
wsCopy.Name = "xxx"
wsCopy.Pictures(0).IsLocked = False
wsCopy.Pictures(0).Move(35, 0)
wbCopy.Save("C:\\Test2.xlsm", FileFormatType.Excel2007Xlsm)
Can you please let me know if I am doing any thing wrong in the above code or please suggest me a solution to move the command button to a different position and it should also retain the click event?
Thanks & Regards,
Padmaja