If I type in a file name to load an *.imr file after my Impromptu catalog is loaded, we have a prompt for a date to be entered. I get a syntax error by doing this way.
Strfilename = ("g:\ filename.imr", "10/15/2014")
The syntax error is generated from Impromptu.
I want to be able to put in the date automatically rather than having to type it.
I haven't programmed Impromptu in over a decade, but I hope this can help you!
Sub passer()
Dim impapp As Object, imprep As Object, cutdate As Variant
On Error GoTo handler
Set impapp = CreateObject("impromptu.application.30")
cutdate = InputBox("Enter date: ")
impapp.Visible 1
impapp.opencatalog "d:\cognos\i66\samples\outdoors.cat", "Creator", "", "", ""
impapp.openreport "d:\cognos\i66\samples\reports\matt.imr", (cutdate)
Set imprep = impapp.activedocument
imprep.exportexcel ("d:\mydocu~1\matt2.xls")
imprep.closereport
Set imprep = Nothing
Set impapp = Nothing
Exit Sub
handler:
MsgBox "Error with " & Error$()
End Sub
The date is a input into a [ prompt ] for the monday for that week. So I load the catalog and the .imr file,,,,,, then you have a prompt that asked for that monday,,, I can generate the Mondays date , and it doesn't matter weather I quote the "date" or value the date I get errors trying to add it to the end of the file name . Just like the way you did it there by adding [ .imr", (date) ]
that doesn't work eather.
Related
I have a question and I don't know if it has an answer.
What I would like to do is track the usage of a macro inside a global variable for an entire day. I want this macro to only be capable of running once a day. I choose if I run it in the morning, noon or evening.
So for example:
Today we are on the 13/01/2022. In the morning I ran this macro and closed the workbook. I want to not be able to run this macro before the 14th (a different day), even if I reopen the Workbook on the 13th in the afternoon, I press the macro button and it won't run.
So I want this macro to check if it was run today and then if the answer is yes to not run, but if the answer is no to run. Can this be done ? I thought about creating a global variable was_run, but how can I store its value even when the workbook is closed and reopen again ? Is this possible ?
Thank you for your help !
Please, try the next way:
Sub myMacroRunningOnlyOncePerDay()
Const myApp As String = "My Daily Variable", Sett As String = "Settings"
Const strDate As String = "myDailyValue"
Dim RegValue As String, NoRun As Boolean
RegValue = GetSetting(myApp, Sett, strDate, "No value")
If RegValue <> "No value" Then
If IsNumeric(RegValue) Then
If CLng(RegValue) = CLng(Date) Then NoRun = True
End If
End If
If NoRun Then Exit Sub
SaveSetting myApp, Sett, strDate, CStr(CLng(Date))
MsgBox "It runs..."
End Sub
It should be good to place the constants (Registry keys) on top of the module (in the declarations area). In this way you can use them from different Subs.
I am trying to build a blank SQL connection in Excel that will be updated with a connection string and command text a later point in the report.
Code I am trying to use:
Workbooks("WorkBook1.xlsm").Connections.Add2 "Test1", "Test1", " ", " ", "SQL"
Syntax from Microsoft:
Add2 (string Name, string Description, object ConnectionString, object CommandText, object lCmdtype, object CreateModelConnection, object ImportRelationships);
However, I am struggling with the syntax as I keep getting errors.
Any ideas?
So this isn't really an answer but rather a work around.
Sub Add_Connection()
Workbooks("WorkBook1.xlsm").Connections.AddFromFile _
"C:\Document\template_Connection.odc"
With ActiveWorkbook.Connections("template")
.Name = "Facility"
.Description = ""
End With
End Sub
I have a saved connection on my computer that I add and rename.
I have multiple text files that are generated everyday.
I would like to search "apple" string from the latest modified text file.
If the string is not found, i will need to search from yesterday's text file.
If it still not found, i will need to search from day before yesterday's text file. The process keep going until i find the string.
Take an example:
Text file created today named : 08112018.txt
Text file created yesterday named : 08102018.txt
Text file created day before yesterday named : 08192018.txt
I will start my search for "apple" in 08112018.txt first.
If it's not found, i will search "apple" in 08102018.txt.
The process continues until "apple" is found.
Here's what I think will give you the best result:
Start by listing all your files into a disconnected record set:
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set list = CreateObject("ADOR.Recordset")
list.Fields.Append "name", 200, 255
list.Fields.Append "date", 7
list.Open
For Each f In fso.GetFolder("C:\your-folder-location").Files
list.AddNew
list("name").Value = f.Path
list("date").Value = f.DateLastModified
list.Update
Next
list.MoveFirst
You can then sort those by date last modified:
list.Sort = "date DESC"
Now you can start from the top of the list and work your way through.
Dim foundApple
list.MoveFirst
Do Until list.EOF Or foundApple
Do Until objTextFile.AtEndOfStream
Set objTextFile = fso.OpenTextFile(list("name"), ForReading)
strLine = objTextFile.ReadLine()
If InStr(strLine, "apple") <> 0 then foundApple = True
Loop
' If foundApple = True Then (Do whatever stuff you need)
list.MoveNext
Loop
list.Close
I've just brain-dumped this code. It's not tested. YMMV.
I am trying to log on to SAP. The Excel VBA code gives me a popup window confirming my information however when I submit the form it does not take me to a new SAP window.
Additionally is there a way to automate all the popup boxes asking for confirmation on my information? I want this code eventually to run at certain times of the day, and I might not be available to input any data.
Sub login1()
Dim sap As Object
Dim conn As Object
Set sap = CreateObject("SAP.Functions")
Set conn = sap.Connection
conn.System = "System Test Environment"
conn.client = "100"
conn.user = "user"
conn.Password = "password"
conn.Language = "EN"
If conn.logon(0, False) <> True Then
MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"
Else
End If
End Sub
This Macro will never open a SAP Window - it will create an SAP-Object within VBA where you can work with SAP-RFC-Functions. (Reading Data from SAP, Writing Data into SAP)
In your version the SAP connection will be unaccessible after "End Sub". You have to declair the Object outside the sub.
This works silent (without dialog) for me:
Dim sap As Object
Public Function login1() As Boolean
Set sap = CreateObject("SAP.Functions")
sap.Connection.System = "System Test Environment"
sap.Connection.client = "100"
sap.Connection.user = "user"
sap.Connection.Password = "password"
sap.Connection.Language = "EN"
If sap.Connection.logon(0, False) <> True Then
sap.RemoveAll
MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"
Else
login1 = true
End If
End Function
Public Function SAPLogoff()
On Error Resume Next
sap.RemoveAll
sap.Connection.logoff
LoggedOn = False
Set sap = Nothing
'Set conn = Nothing
End Function
Since you want to "open a new SAP Window" you have to make a different approach!
At First try to open the new instance of SAP from the DOS Commandline with "sapshcut":
C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapshcut.exe -system="System Test Environment" -client="100" -user="user" -password="password" -language="EN"
If your SystemName has no Spaces (and I belive so!) then you can write it also like:
C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapshcut.exe -system=SystemTestEnvironment -client=100 -user=user -password=password -language=EN
When this call works with your credentials, then you can transfer it to Excel like this:
Sub login1()
Call Shell("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapshcut.exe -system=SystemTestEnvironment -client=100 -user=user -password=password -language=EN",vbNormalFocus)
End Sub
You could also add a transaction by adding "-command=your_tcode" to the String.
If your have spaces in the parameters and you could only start it with -system="System Test Environment" from the Commanline, you will have to escape this in Excel with -system="""System Test Environment""" (!)
Can you please assist with this problem?
Whenever I run this macro, it stops at:
Dim authResult As Dictionary
With an error message of:
Compile error: User-defined type not defined.
I have not used the dictionary type before and I am trying to re-use this code from a sample macro.
The aim of this script is to use excel to make rest calls to a website so that I can download historic data. I am currently stuck at the login section.
Sub Login()
Dim userName As String
Dim password As String
Dim apiKey As String
userName = "username"
password = "password"
apiKey = "key123"
'activityTextbox.Text = ""
'clearData
Dim authResult As Dictionary
Set authResult = restClient.authenticateAccount(userName, password, apiKey)
If Not authResult Is Nothing Then
'appendActivity "Connected"
' Configure Excel to pull streaming updates as often as possible
Application.RTD.ThrottleInterval = 0
' Uncomment for real-time prices - this is very CPU intensive
' Buffer interval defaults to 500ms
'Application.WorksheetFunction.RTD "IG.api.excel.RTD.IGApiRTDServer", "", "bufferInterval", "0"
' Set manual refresh to true from very remote locations
' Application.WorksheetFunction.RTD "IG.api.excel.RTD.IGApiRTDServer", "", "manualRefresh", "true"
' This will require manually calling refresh to update lighstreamer subscriptions, i.e.
' Application.WorksheetFunction.RTD "IG.api.excel.RTD.IGApiRTDServer", "", "refresh"
Dim maxPriceRequestsPerSecond As Double
maxPriceRequestsPerSecond = 0 ' all available updates
If restClient.streamingAuthentication(maxPriceRequestsPerSecond) Then
m_loggedIn = True
'populateWatchlists
'populateAccounts
'manualStreamingRefresh
'Else
' appendActivity "Lightstreamer connection failure"
End If
Else
MsgBox "Authentication failed"
End If
End Sub
Thanks in advance.
Cheers,
Joe
Add a reference to Microsoft Scripting Runtime as #YowE3k said:
In the VBA Editor:
Tools -> References
Find Microsoft Scripting Runtime
Check it
Click okay