Autoit COM Error opening a PPT/PPTX - com

When i try top open the the PPT, instead of creating a new one (which works fine!), I am getting the following error
$objPPT = _PPT_PowerPointApp()
If #error Then
MsgBox(0,"","No PowerPoint available")
Exit
EndIf
$PresInterface = _PPT_CreatePresentation($objPPT) ;Get presentation
interface$objPres = _PPT_PresentationOpen($PresInterface,"C:\Users\s.mailappan\Desktop\3G-Reports\MyAutoItPresentation.ppt") ;Add a new presentation

To open an existing PPT, need to get rid of the following line from my original code.
$PresInterface = _PPT_CreatePresentation($objPPT) ;Get presentation
Which makes the following code to work.
$objPPT = _PPT_PowerPointApp()
If #error Then
MsgBox(0,"","No PowerPoint available")
Exit
EndIf
$objPres = _PPT_PresentationOpen($objPPT,"C:\Users\s.mailappan\Desktop\3G-Reports\MyAutoItPresentation.ppt") ;Add a new presentation

Related

open xlsx in libreoffice macro

I am trying to open an excel file from libreoffice calc's macro but I keep coming accross errors. This is my first time using libreoffice macro.
Here is my first attempt, was from a website where someone asked the same question so I tried there code: https://forum.openoffice.org/en/forum/viewtopic.php?f=5&t=17075
Target = "C:\Users\RKerrigan\Documents\Scripts\Mailerreportgenerator\Miller Radiology Mailers Template.xlsx"
TargetURL = convertToURL(Target)
Empty() = Array()
TestDoc = StarDesktop.loadComponentFromURL(TargetURL, "_blank", 0, Empty())
But the error I got was regarding line 6 (Empty() = Array()):
BASIC runtime error.
'382'
This property is read-only.
So then I searched around and found this link from stackoverflow: https://stackoverflow.com/a/65201568/16953756
Which brings you to this example:https://help.libreoffice.org/6.4/en-US/text/sbasic/shared/stardesktop.html
Dim docURL As String
Dim doc As Object, docProperties()
docURL = ConvertToURL("C:\\Users\\RKerrigan\\Documents\\Scripts\\Mailerreportgenerator\\Miller Radiology Mailers Template.xlsx")
Rem com.sun.star.frame.Desktop
doc = StarDesktop.LoadComponentFromURL(docURL, "_blank", 0, docProperties)
But I got another error saying:
BASIC runtime error.
'1'
Type: com.sun.star.lang.IllegalArgumentException
Message: Unsupported URL <file:///C://Users//RKerrigan//Documents//Scripts//Mailerreportgenerator//Miller%20Radiology%20Mailers%20Template.xlsx>: "type detection failed"
Can someone help me open this file in libreoffice macro? "C:\Users\RKerrigan\Documents\Scripts\Mailerreportgenerator\Miller Radiology Mailers Template.xlsx"
I thought it was something quotes so I tried double slashes and that didn't work either.
Please try
Sub OpenRadiologyMailers()
Dim sFilename As String
Dim oSourceSpreadsheet As Variant
sFilename = ConvertToURL("C:\Users\RKerrigan\Documents\Scripts\Mailerreportgenerator\Miller Radiology Mailers Template.xlsx")
If Not FileExists(sFilename) Then
MsgBox("File not found!")
Exit Sub
EndIf
GlobalScope.BasicLibraries.loadLibrary("Tools")
oSourceSpreadsheet = OpenDocument(sFilename, Array())
If IsEmpty(oSourceSpreadsheet) Then
MsgBox("The file may be open in another application",0,"Failed to load file")
Exit Sub
EndIf
' ... further actions with the document oSourceSpreadsheet
End Sub

Excel 'Cancel' button breaks entire application

Having trouble with calling an endpoint (connectionStringURI = http:\company.com:8000/Prices?format=csv&Transaction.ID=5456, e.g.). Call it with this code:
Set curveSource = curveDestination.QueryTables.Add(Connection:="TEXT;" & connectionStringURI, Destination:=DestinationSheet.Range("A1:F3000"))
curveSource.Name = "Prices"
curveSource.TextFileParseType = xlDelimited
curveSource.TextFileCommaDelimiter = True
curveSource.Refresh BackgroundQuery:=False
curveSource.SaveData = True
The call to the URI returns a csv file. Everything works great. When this code is hit:
curveSource.Refresh BackgroundQuery:=False
I see an Excel dialogue box that says, "Contacting the server for information", and it has a 'Cancel' button on it. If the user does nothing, it displays the data properly in the DestinationSheet. If the user clicks the 'Cancel' button while this is occurring, it breaks the entire spreadsheet. From then on, it throws an error at
curveSource.Refresh BackgroundQuery:=False
The error is, "Run-time error: '1004'. Excel cannot find the text file to refresh this external data range". The user has to close the file the Excel file and reopen it to get it to work. Can't find anything about this error after hours of googling.
I've tried setting everything to Nothing, removing QueryTables, very frustrating. Nothing seems to fix the issue.
Any ideas ?
Not sure if this would help but you can try Application.DisplayAlerts = False before that line, and revert back to True afterwards maybe. And/or On Error Resume Next before the line that give the error and On Error Goto 0 afterwards.

Setting AutoCAD ActiveSpace to ModelSpace VB.NET

I am trying to ensure that I am addressing entities in ModelSpace, but I get an exception that gives no hint at what the problem is because it's a COM object I guess. Does anyone know what I might be doing wrong? If I take out that line (and the zoom extents line) the remaining code works just fine, so I know my document object is being set correctly.
Dim acDWG As AutoCAD.AcadDocument
' open the drawing
acDWG = acApp.Documents.Open(dgvr.Cells("FullName").Value.ToString)
' ensure the drawing has the modelspace tab activated (doesnt work)
acDWG.ActiveSpace = AutoCAD.AcActiveSpace.acModelSpace
' zoom to extents (sometimes works, sometimes not) '
acApp.ZoomExtents()
' build a selectionset of all blocks named 'Solid1' and then delete them all
Dim ss As AutoCAD.AcadSelectionSet = acDWG.SelectionSets.Add("DELETE")
Dim gpCode(1) As Int16
Dim dataValue(1) As Object
gpCode(0) = 0 : dataValue(0) = "Insert"
gpCode(1) = 2 : dataValue(1) = "Solid1"
ss.Select(AutoCAD.AcSelect.acSelectionSetAll,,, gpCode, dataValue)
ss.Erase()
ss.Delete()
ss = Nothing
Update: I discovered why I am getting the error. The code is correct, but the problem is that the drawing has not completed opening yet. If I put a "wait for 5 seconds" line of code directly after the Open line, it works just fine. So it seems my question is how to open the drawing and have VB.Net wait for a signal from the COM object that it is "ready to continue"? (not sure how to word it)
Use a combination of Do...Loop and a Try...Catch block to "wait" like this:
Dim acDWG As AutoCAD.AcadDocument
acDWG = acApp.Documents.Open(dgvr.Cells("FullName").Value.ToString)
Dim bOpen As Boolean = False
Do Until bOpen = True
Try
acDWG.ActiveSpace = AutoCAD.AcActiveSpace.acModelSpace
bOpen = True
Catch ex As Exception
' ignore the error and try again until it is open
End Try
Loop

Disable Alert message of a webpage using VBA code

I am opening a webpage using VBA code which contains form where data will be filled by user. I have excel file which contains data. I write VBA code that read the data from excel and put it on webpage. After filling information on webpage I click on Save button. All this work I had done using VBA code so that it can be done automatically. I have 500 users data hence I run the loop 500 times. All it done fines.
Only one problem come and it is that after filling data in webpage form when I click on save button a popup message comes "Your data saved successfully". It has "OK" button. Now my program stops here and need user intervention to manually click on "OK" button.
Is there any way using VBA code by which we can stop this popup message box, so that manual intervention is no longer required?
I read the webpage and Javascript written for webpage also. I found that when Save button is clicked a function called savedetails() . Inside this function a alert() function is there. Sample code here
function saveDetails()
{
/* get details of member*/
---
---
---
---
---
if (xml.status == 200 || window.location.href.indexOf("http") == -1) {
var successCode = "";
alert("Data Saved Successfully");
var tes = xml.responseText;
/* if (successCode == '1') { */
document.webDataForm.submit();
remove_popup();
};
}
VBA Code For Each htmlInput In htmlColl
If Trim(htmlInput.ID) = "btn" Then
If Trim(htmlInput.Name) = "btnfinal" Then
htmlInput.Click 'After this "Data Saved Successfully popup message comes and program need user intervention
temp = htmlInput.getAttribute("onClick")
MsgBox temp
'IE.document.getElementById("clearRelItems").removeAttribute ("o n C l i c k")
'Call iedoc.parentWindow.execScript("window.confirm = function saveBankDetails() {return true}", "JavaScript") // Not worked
'htmlInput.removeAttribute ("onClick") //Not worked
'htmlInput.setAttribute "onClick", "return TRUE" //Not worked
'Application.SendKeys "{ENTER}", True // Not worked
Exit For
End If
End If
Next htmlInput
You could try wrapping the line with the Application.DisplayAlerts function that produces the display box you don't want;
eg.
If Trim(htmlInput.ID) = "btn" Then
If Trim(htmlInput.Name) = "btnfinal" Then
Application.DisplayAlerts = False
htmlInput.Click
Application.DisplayAlerts = True
.... Further Code
I had this problem and the only way I could solve it was by writing a vb script that identifies the pop up and closes it...
After that, you just need to call it from your vba code.

How to stop a Word Document immediately when newly created

I have a VS2010 Vb.net program that creates a Word 2007 file.
My Normal.dot file is customised to give me a new Tab with Buttons in that do specific things via VBA in the Normal.dot program when those Buttons are pressed.
This all works fine, however, I now want to add some functionality whereas as soon as the new Word document is created, it edits a Task in Outlook.
I have edited the 2 "This Document" Procedures and you can see my Normal.Dot file in the attached Screenshot.
When I run my VB.Net program to create a brand new Word 2007 document, the program does NOT stop on either of the message boxes, it just continues and opens the Word document as before, my code is below, what am I doing wrong ?!?
'Open or Create Word document for Editing
myNewsLetter = myFolder + myLeague + "News" + mySession + ".doc"
If File.Exists(myNewsLetter) Then
'do nothing
Else
myTemplate = myTempFolder + "NL Skeleton.doc"
File.Copy(myTemplate, myNewsLetter)
Create_Blank_Newsletter()
End If
'Open Word Newsletter, or switch to it if it's already open
Dim myFileOpen As Boolean
myFileOpen = IsFileOpen(myNewsLetter)
If myFileOpen = False Then
MSDoc = MSWord.Documents.Open(myNewsLetter)
End If
MSWord.WindowState = Word.WdWindowState.wdWindowStateNormal
MSWord.Visible = True
MSWord.ActiveDocument.Bookmarks("\StartOfDoc").Select()
OK, sorted this, the full discussion can be found here ... http://www.vbaexpress.com/forum/showthread.php?p=286771#post286771
Basically, I'm not creating a NEW document, I am creating a new document via a Copy and then opening that existing document !!!