|
<pre>Hi,
I am pretty new to VBscripts. I am trying to use a VBscript to copy calendar entries from an excel spreadsheet into an Outlook Calendar. I have found on forums this script below:
Dim objExcel, objWorkbook
Dim objOutlook, objNameSpace, objFolder, foundItems, objAppt
Dim i, j, strFilter
Const olFolderCalendar = 9
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.DisplayAlerts = False
Set objWorkbook = objExcel.Workbooks.Open("C:\VBATest\Dates.xlsx")
objExcel.Application.Visible = False
'objExcel.ActiveWorkbook.Save'
Set objOutlook = CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.GetNameSpace("MAPI")
Set objFolder = objNameSpace.GetDefaultFolder(olFolderCalendar)
For i = 1 To 3
j = 1
While j > 0
strFilter = "[Start] >= 'objWorkbook.Worksheets(i).Cells(4,2)' AND [Start] <= 'objWorkbook.Worksheets(i).Cells(4,3)' AND [Subject = 'objWorkbook.Worksheets(i).Cells(6,j)'"
Set foundItems = objFolder.Items.Restrict(strFilter)
Set foundItems = objFolder.Items.Restrict(strFilter)
If foundItems.Count = 1 Then foundItems.Item.Delete
Set objAppt = objFolder.Items.Add
With objAppt
.Subject = "objWorkbook.Worsheets(i).Cells(6,j)"
.Body = "objWorkbook.Worsheets(i).Cells(6,j)"
.Start = "objWorkbook.Worsheets(i).Cells(7,j)"
.AllDayEvent = True
.ReminderMinutesBeforeStart = 1440
.Save
End With
Set j = j + 1
If objWorkbook.Worksheets(i).Cells(6, j) = "stop" Then Set j = 0
If objWorkbook.Worksheets(i).Cells(6, j) = "stop" Then j = 0
Wend
Next
objWorkbook.Close False
Set objExcel = Nothing
Set objWorkbook = Nothing
Set objOutlook = Nothing
Set objNameSpace = Nothing
Set objFolder = Nothing
Set objAppt = Nothing
but I get the below error:
Error on line 20: Cannot parse condition. Error at "[Subject = 'objWorkbook.Worksheets(i).Ce...".
Code 80020009.
Any ideas how I can resolve this?</pre>
|
|
|
|
|
Have you took a look at/with the debugger to see what is (perhaps) missing ?
From where have you got this code-line :
strFilter = "[Start] >= 'objWorkbook.Worksheets(i).Cells(4,2)' AND [Start] <= 'objWorkbook.Worksheets(i).Cells(4,3)' AND [Subject = 'objWorkbook.Worksheets(i).Cells(6,j)'"
|
|
|
|
|
You dont need the quotes in these lines and you have misspelled Worksheets as Worsheets
.subject = "objWorkbook.Worsheets(i).Cells(6,j)"
.Body = "objWorkbook.Worsheets(i).Cells(6,j)"
.Start = "objWorkbook.Worsheets(i).Cells(7,j)"
Change them to:
.Subject = objWorkbook.Worksheets(i).Cells(6,j)
.Body = objWorkbook.Worksheets(i).Cells(6,j)
.Start = objWorkbook.Worksheets(i).Cells(7,j)
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
... and Start and Subject are used before they are assigned ...

|
|
|
|
|
In addition to the answer above, your filter is wrong. You're missing the closing ] around Subject , and you're searching for the literal string objWorkbook.Worksheets(i).Cells(6,j) rather than the value of that cell.
strFilter = "[Start] >= '" & objWorkbook.Worksheets(i).Cells(4,2) & "' AND [Start] <= '" & objWorkbook.Worksheets(i).Cells(4,3) & "' AND [Subject] = '" & objWorkbook.Worksheets(i).Cells(6,j) & "'"
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
 Thanks for all the suggestions. I have made some of the amendments suggested and the code looks like this:
Dim objExcel, objWorkbook
Dim objOutlook, objNameSpace, objFolder, foundItems, objAppt
Dim i, j, strFilter
Const olFolderCalendar = 9
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.DisplayAlerts = False
Set objWorkbook = objExcel.Workbooks.Open("C:\VBATest\Dates.xlsx")
objExcel.Application.Visible = False
'objExcel.ActiveWorkbook.Save'
Set objOutlook = CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.GetNameSpace("MAPI")
Set objFolder = objNameSpace.GetDefaultFolder(olFolderCalendar)
For i = 1 To 3
j = 1
While j > 0
strFilter = "[Start] >= '" & objWorkbook.Worksheets(i).Cells(4,2) & "' AND [Start] <= '" & objWorkbook.Worksheets(i).Cells(4,3) & "' AND [Subject] = '" & objWorkbook.Worksheets(i).Cells(6,j) & "'"
Set foundItems = objFolder.Items.Restrict(strFilter)
Set foundItems = objFolder.Items.Restrict(strFilter)
If foundItems.Count = 1 Then foundItems.Item.Delete
Set objAppt = objFolder.Items.Add
With objAppt
.Subject = objWorkbook.Worksheets(i).Cells(6,j)
.Body = objWorkbook.Worksheets(i).Cells(6,j)
.Start = objWorkbook.Worksheets(i).Cells(7,j)
.AllDayEvent = True
.ReminderMinutesBeforeStart = 1440
.Save
End With
Set j = j + 1
If objWorkbook.Worksheets(i).Cells(6, j) = "stop" Then Set j = 0
If objWorkbook.Worksheets(i).Cells(6, j) = "stop" Then j = 0
Wend
Next
objWorkbook.Close False
Set objExcel = Nothing
Set objWorkbook = Nothing
Set objOutlook = Nothing
Set objNameSpace = Nothing
Set objFolder = Nothing
Set objAppt = Nothing
I now get the error Line 20 Error: Condition is not valid.
Any ideas?
|
|
|
|
|
Probably a problem with your date formats:
Filtering Items Using a Date-time Comparison[^]
NB: That uses VBA's Format function, which isn't availble in VBScript. You'll need to use FormatDateTime[^] instead:
Dim minDate, maxDate
minDate = FormatDateTime(objWorkbook.Worksheets(i).Cells(4,2), 0)
maxDate = FormatDateTime(objWorkbook.Worksheets(i).Cells(4,3), 0)
For i = 1 To 3
j = 1
While j > 0
strFilter = "[Start] >= '" & minDate & "' AND [Start] <= '" & maxDate & "' AND [Subject] = '" & objWorkbook.Worksheets(i).Cells(6,j) & "'"
...
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I need to load some icons in jp2 format into an ImageList.
I searched online for a solution, but everything I've found is out of date (I'm using Visual Studio VB 2017.)
There's a free DLL called "FreeImage" for reading & converting image formats, but all VB/.Net code is out of date and the documentation sux rocks. (Images as loaded as "Long" values???)
I've resorted to a simple CLI utility called "ImageMagick" that can I can call from VB to convert jp2's to png's that I can then load normally. This works, but is much too slow if you have a lot of files.
I don't need to manipulate the images in any way, and don't need to save them. I only need to be able to load them.
TIA
|
|
|
|
|
Message Removed
modified 6-Mar-18 16:02pm.
|
|
|
|
|
When i click browse button instead of opening document folder, It should open as per configured path.
Can some one please help me.
|
|
|
|
|
|
<pre lang="text">I am using WebClient.UploadFile to upload local files to a Hostmonster web server. I have code that downloads files from my website correctly but I am new to uploading. If doesn't seem very difficult but I just can't get it to work. I have basically copied the vb.net code from https://msdn.microsoft.com/en-us/library/36s52zhs(v=vs.110).aspx. I am using server side code located in the same folder that the file is being transferred to, referred to as Upload.net and listed below.
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Net"%>
<%@ Import NameSpace="System.Web"%>
<Script language="VB" runat=server>
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim f As String
Dim file
For Each f In Request.Files.AllKeys
file = Request.Files(f)
file.SaveAs(Server.MapPath("~/data/" & file.FileName)
Next f
End Sub
</Script>
<html>
<body>
<p> Upload complete. </p>
</body>
</html>
Function TestWcWrite()
Dim LoginUser As String = "testuser"
Dim UserPassword As String = "testpass"
Dim UrlLicensePath As String = "http://www.xxx.com/data/"
Using wc As New System.Net.WebClient()
ServicePointManager.ServerCertificateValidationCallback =
New System.Net.Security.RemoteCertificateValidationCallback(AddressOf CertificateValidation)
wc.Credentials = New System.Net.NetworkCredential(LoginUser, UserPassword)
Dim responseArray As Byte() = wc.UploadFile(UrlLicensePath & "upload.net", "POST", "C:\temp\test.txt")
Console.WriteLine(ControlChars.Cr & "Response Received.The contents of the file uploaded are: " &
ControlChars.Cr & "{0}", System.Text.Encoding.ASCII.GetString(responseArray))
wc.Dispose()
End Using
End Function
The folder I am loading to is password protected and the permissions are set to 777 at this point. I was using Https originally so that is why the RemoteCertificateValidationCallback is in the code. Anyway when I execute the code, the file isn't copied and the response returned is the contents of upload.net file. What am I missing here? Obviously it is something minor.
Thanks for your help,
Bob
|
|
|
|
|
In an existing vb.net 2010 desktop application, I have users that would like all the screens to be larger since some of them say the cannot see the screens.
Thus is there something like a 'zoom' enlarge feature that can be added to the application without having to enlarge all the screens in the application? If so, can you tell me how to accomplish this goal?
If not, would you tell me that also?
|
|
|
|
|
Even better; Windows has some tools built-in to help people with visual limitations, including a magnifier[^]. If that doesn't help them enough, you could change the DPI-setting and/or change the color-scheme to a high-contrast version.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The problem is the user has no problems with the other applications. They only want application size to be increased.
|
|
|
|
|
This is usually not a problem that a user has "per application"; sorry, but can't help there.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The first thing you need to do is to look at your GUI design to see why the "screens" (not sure what you mean by that) are so small that users cannot see them.
|
|
|
|
|
Hi All.
I Want to use VBA code to get data from Oracle DB The code is here but I fail
Const IPServer = "123.168.YY.XXX" ' Server hosting the Oracle db
Const DBNAME = "NMS" '"DatabaseName"
Const ORACLE_USER_NAME$ = "user"
Const ORACLE_PASSWORD$ = "pass"
Const port = "1521"
Sub ConnectTOOracle()
Dim oRs As ADODB.Recordset
Dim oCon As ADODB.Connection
Set oCon = New ADODB.Connection
Dim mtxData As Variant
Dim strConOracle As String
strConOracle = "Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) "
strConOracle = strConOracle & "(HOST=" & IPServer & ")(PORT=port))(CONNECT_DATA=(SERVICE_NAME=" & DBNAME
strConOracle = strConOracle & "))); uid=" & ORACLE_USER_NAME & " ;pwd=" & ORACLE_PASSWORD & ";"
oCon.Open strConOracle
'Cleanup in the end
Set oRs = Nothing
Set oConOracle = Nothing
End Sub
Please help.
|
|
|
|
|
hmanhha wrote: but I fail Yes, you fail to tell us what the problem is. However, looking at your code I get the feeling that
")(PORT=port))(CONNECT_DATA=(SERVICE_NAME="
is not correct. Probably should be:
")(PORT=" & port & "))(CONNECT_DATA=(SERVICE_NAME="
|
|
|
|
|
Thanks.
I have modify it.
But the problem the same.
Run-Time error '-2147467259 (80004005':
[Microsoft][ODBC Driver manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV failed.
And warning
Microsoft ODBC for Oracle.
The Oracle (tm) client and networking componets were not found.
These components are supplied by Oracle......
|
|
|
|
|
Plug the warning into google and you will find there are some components you need to source from oracle, just like the warning says.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Good day! I have been trying to build an application in MapWinGIS and Visual Basic. I already added Map Control in the Toolbox and made a form. There are no codes yet but I encountered a problem. It says:
InvalidOperationException was unhandled
An error occurred creating the form. See Exception.InnerException for details. The error is: Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
I have VB 2008 Express Edition, MapWinGIS v4.9.4.2 32-bit and Windows 8.1.
Thank you!
Andrea
|
|
|
|
|
SO I'm trying to connect to a SAP Business One Service Layer - according to their documentation:
> Before you perform any operation in Service Layer, you first need to log into Service Layer.
> Send this HTTP request for login:
> POST https://<server name="" ip="">:<port>/b1s/v1/Login
{"CompanyDB": "US506", "UserName": "manager", "Password": "1234"}
So, using the code from MS docs[^]
Dim request As WebRequest = WebRequest.Create("https://xxxxxxxx:port/b1s/v1/Login")
request.Method = "POST"
Dim postData As String = "{""CompanyDB"": ""XXXX"", ""UserName"": ""XXXX"", ""Password"": ""XXXX""}"
' have alternbatively tried the below - no difference in the result though
' Dim postData As String = New JavaScriptSerializer().Serialize("{""CompanyDB"": ""XXXX"", ""UserName"": ""XXXX"", ""Password"": ""XXXX""}")
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
request.ContentType = "application/json; charset=utf-8"
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As WebResponse = request.GetResponse()
Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
Console.WriteLine(responseFromServer)
reader.Close()
dataStream.Close()
response.Close()
And all I get back is "The remote server returned an error: (400) Bad Request.". Why??
I know a connection is possible, because I can connect using the Chrome extension Postman, using the same JSON data.
....
[edit] bugger something's come up and I have to pop out for a couple of hours. Apologies in advance if someone does answer and I'm not here....
modified 18-Aug-17 11:49am.
|
|
|
|
|
The first problem I see is that you're using a Javascript serializer to serialize the exact string you're supposed to be sending in the request. Don't serialize that string. Just send the string!
|
|
|
|
|
Hi
thanks - but that line was REM'd out, and was just an alternative I'd tried I desperation... - the actual line used is simply
Dim postData As String = "{""CompanyDB"": ""XXXX"", ""UserName"": ""XXXX"", ""Password"": ""XXXX""}"
and that is was is POSTed
...
|
|
|
|