Hello everyone! I am currently attempting to export data to Excel from WinCC. I have created a global action that runs every second to create a new Excel file per minute and update it every second. However, I am facing issues with saving changes to Excel. Can anyone provide assistance with this issue? Here is the code I am using: Option Explicit Function action Dim Dat Dim Sec Dim Min Dim Exce Dim SheetNam Dim i Dim fso Dim WB Dat = FormatDateTime(Now, vbShortDate) Sec = Second(Now) Min = Minute(Now) SheetNam = "Report" Set Exce = CreateObject("Excel.Application") Set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists("C:\Users\User\Desktop\excel\"&Min&".xlsx") Then Set WB = Exce.Workbooks.Open("C:\Users\User\Desktop\excel\"&Min&".xlsx") Exce.Application.DisplayAlerts = False Exce.Application.Visible = False 'write data to Excel workbook Exce.ActiveWorkbook.Save "C:\Users\User\Desktop\excel\"&Min&".xlsx" Exce.ActiveWorkbook.Close Exce.Quit Else Exce.Application.Visible = False Exce.Workbooks.Add Exce.Worksheets(1).Name = SheetNam Exce.Worksheets(SheetNam).Range("A1") = "Create" Exce.Worksheets(1).SaveAs("C:\Users\User\Desktop\excel\"&Min&".xlsx") Exce.ActiveWorkbook.Close Exce.Quit End If End Function If you have any insights or suggestions, please feel free to share. Thank you for your help.
Dear, I am interested in creating a SQL Server query within WinCC RT Advanced, and then exporting the results to Excel. How can I accomplish this task efficiently?
It appears you might be running into trouble with Excel not being completely closed off in your code. Add Set Exce = Nothing after Exce.Quit, this will ensure the Excel process is fully terminated. Furthermore, the issue might be in the 'write data to Excel workbook' section, which you haven't shared here, so double-check that part too. Finally, ensure your file path is correct and accessible without requiring any additional permissions.
It seems like your script is not saving the workbook correctly. In VBA, the proper command for saving an existing workbook is "Workbook.Save". Currently, you are using "Exce.ActiveWorkbook.Save" followed by the file directory, which may not work as expected. Try replacing your save commands with just "WB.Save" (since you've already defined the Workbook as WB) and see if that resolves your issue. You should also ensure that the file does not remain open in the background somewhere, as it can cause saving problems too. Lastly, consider handling your Excel object shutdowns more gracefully - it's a good practice to use "Set WB = Nothing" and "Set Exce = Nothing" after your .Quit commands.
Hey! It looks like you're on the right track with your code, but I noticed a couple of things that might help. First, make sure you're actually writing any data to the Excel sheet before saving it. Also, instead of using `Exce.ActiveWorkbook.Save`, try using `WB.Save` after opening or creating the workbook to avoid any confusion with active workbooks. Lastly, ensure that you properly handle any potential errors by adding error-checking logic, which can be super helpful in troubleshooting issues down the line. Good luck!
It looks like you're on the right track, but there are a couple of things you might want to check. First, ensure that your paths and permissions are all set correctly; sometimes saving issues arise from trying to access folders without proper permissions or specifying incorrect paths. Additionally, you might want to consider adding some error handling to understand better what's going wrong when saving. For example, you could log any errors encountered when trying to save the workbook. Finally, it may help to call `Exce.Quit` only after ensuring all operations are complete, which can prevent Excel from closing prematurely. Hope this helps!
Hey! It looks like you're on the right track, but I noticed a couple of potential issues. First, when you save the workbook using `Exce.ActiveWorkbook.Save`, it’s better to just use the `WB` object for clarity. Also, make sure you include proper error handling to catch any issues when opening or saving the file—this can help diagnose what's going wrong. Additionally, try setting `Exce.Visible` back to `True` before debugging to see if that reveals any error messages in Excel. Lastly, you might want to check if you have file permission issues that might prevent saving. Good luck!
Hey there! It looks like you’re on the right track, but I noticed a couple of potential issues. First, make sure you have the correct permissions to save files in the specified directory, as that can cause saving errors. Additionally, instead of closing and quitting the Excel application every second, try keeping it open throughout the minute and just updating the data within the same instance. This should improve performance and help with save issues. Also, ensure that you're properly releasing any COM objects to avoid memory leaks. I hope this helps!
✅ Work Order Management
✅ Asset Tracking
✅ Preventive Maintenance
✅ Inspection Report
We have received your information. We will share Schedule Demo details on your Mail Id.
Answer: - The issue with saving changes to Excel could be due to the way the Excel workbook is being handled in your VBS script. Ensure that the workbook is properly opened, data is written correctly, and the workbook is saved and closed appropriately.
Answer: - To troubleshoot Excel export issues, you can check the code logic, verify file paths and permissions, confirm data is being written correctly to the Excel workbook, and ensure proper handling of the Excel application instance.
Answer: - If your VBS script is not updating the Excel file every second as intended, review the code logic related to updating the Excel file within your global action. Check for any potential errors that may be preventing the continuous updates.
Answer: - If your VBS script is not creating a new Excel file per minute, verify the conditions for creating a new Excel file, check the file naming convention, and ensure that the file creation process is correctly implemented within the script.
Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.