|
You will nead to create an Excel application - Look here for some examples[^]
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Okay, slowly getting there. This is what I have:
Dim xlApp, xlWkb, SourceFolder,TargetFolder,file
Set xlApp = CreateObject("excel.application")
Set fs = CreateObject("Scripting.FileSystemObject")
Const xlNormal=1
filestr="D:\some directory\some file.xml"
TargetFolder="D:\some directory\xls"
xlApp.Visible = False
Set xlApp = CreateObject("Excel.Application")
Set xlWkb = xlApp.Workbooks.OpenXML(filestr, Array(1), 2)
BaseName= fs.getbasename(filestr)
FullTargetPath=TargetFolder & "\" & BaseName & ".xls"
xlWkb.SaveAs FullTargetPath, xlNormal
xlWkb.close
Set xlWkb = Nothing
Set xlApp = Nothing
Set fs = Nothing
End Sub
This will open the XML fiel, apply the style sheet and save it as a workbook. However, the code is interrupted by the opo-up window in Ezxcel prompting the user to apply the XSL fiel or not. The code continues only after clicking 'OK'. The code needs to run uninterrupted. Parameter 3 of OpenXML should be the load method: 2 = xlXmlLoadImportToList. Not sure I am using the correct parameter?
|
|
|
|
|
Okay, this seems like a confirmed bug:
http://support.microsoft.com/kb/307230/en-US
The solution is to convert to HTML first, then to xls. The workaround code in VBA:
Sub Macro3()
Dim oXML As Object, oXSL As Object
Set oXML = CreateObject("MSXML.DOMDocument")
Set oXSL = CreateObject("MSXML.DOMDocument")
oXML.Load "c:\customers.xml"
oXSL.Load "c:\customers.xsl"
Dim sHTML As String
sHTML = oXML.transformNode(oXSL)
Open "c:\customers.htm" For Output As #1
Print #1, sHTML
Close #1
Dim oApp As Excel.Application
Set oApp = CreateObject("excel.application")
oApp.Visible = True
oApp.Workbooks.Open "c:\customers.htm"
End Sub
This fails when trying to save the HTML file, presumably because the file cannot be referenced that way in VBScript:
Open "c:\customers.htm" For Output As #1
What do I need to change to save this as HTML?
p.s. I realise this forum is VB but I could not find a disgnated VBScript section
|
|
|
|
|
It fails because you shouldn't write in the root. The PC will explode if you do that.
Member 10666698 wrote: p.s. I realise this forum is VB but I could not find a disgnated VBScript section No surprise there, VBA has been abandoned with VB6.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
While that is good to know I still have no idea how to do this in VBScript. Assume I know nothing about VBScript
|
|
|
|
|
|
Second sentence in that link: Despite Microsoft's best efforts to kill VBA off
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
how to read any specific text from Web Browser tool and put it into TextBox control.
it would be better it you tell me how can i read text line by line from Web Browser tool and put it into TextBox control.
thanks,
Virendra
|
|
|
|
|
Virendra Singh Bhanu wrote: it would be better It would be better if you posted in the ASP.NET forum[^].
|
|
|
|
|
but i don't know ASP.Net
is it not possible in vb.net?
|
|
|
|
|
You have not explained in any detail what you mean by "read line by line from Web Browser tool". However, I would suggest using the WebBrowser Class[^], which allows you to interact with any internet site.
|
|
|
|
|
Did you mean from the WebBrowser control? Or from any browser-application that the user has opened?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
Let's say that I have an object called Employee with the properties Name and Department.
Next I have a List(Of Employee) with say 5 employees in it. Each of these 5 employees are member of one of 10 possible different departments. Perhaps they are each member of a different department, perhaps they are all members of the same department, etc. This is an unknown.
How can I get the distinct departments from my list ?
There is List.Distinct, but it seems I can only get distinct entire objects (employees) through that.
Any help much appreciated.
Best regards,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Probably by creating another List (or other collection class) which only contains departments. Go through all your employee records adding the department to the second list.
|
|
|
|
|
|
Johan Hakkesteegt wrote: Each of these 5 employees are member of one of 10 possible different departments. Perhaps they are each member of a different department, perhaps
they are all members of the same department, etc. This is an unknown. One employee in one department, not one employee in multiple departments. Check.
Imports System.Collections.Generic
Module Module1
Class Employee
Public Property Name As String
Public Property Department As String
End Class
Sub Main()
Dim zeList As New List(Of Employee)
zeList.Add(New Employee() With {.Name = "John", .Department = "IT"})
zeList.Add(New Employee() With {.Name = "Jane", .Department = "IT"})
zeList.Add(New Employee() With {.Name = "Pete", .Department = "Management"})
Dim departments As IEnumerable(Of String) = zeList.Select(Function(e) e.Department).Distinct()
For Each department As String In departments
Console.WriteLine(department)
Next
Console.ReadLine()
End Sub
End Module
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Last night I woke up and figured Richard's answer myself, but this is the "one-liner" that I was after.
Thanks Eddy !
My advice is free, and you may get what you paid for.
|
|
|
|
|
Eddy Vluggen wrote: zeList.Select(Function(e) e.Department).Distinct()
I looked and looked and wondered where the Function(e) comes from and what is it doing x=>
So I have not looked at VB since before linq was invented.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
How do I keep a class object "alive" in a Windows Service?
I have a simple class object (clsWatcher) that monitors a folder using an instantiation of the FileSystemWatcher class. It works great. When a change is made to the folder being "watched" it triggers a log entry.
When I use the clsWatcher as a form-level object in a standard Windows Forms EXE, it works perfectly as long as the windows form is open. When the form closes, it dies and no watching is done. Perfect.
When I transfer this class to a SYSTRAY application, it continues to work correctly. As long as the SYSTRAY application is not exited, the clsWatcher works properly. When I exit the SYSTRAY application, it dies and no watching is done. Perfect.
When I transfer this class to a Windows Service, it does not work as desired. The service starts, the clsWatcher instantiates, and then the service "finalizes" and the clsWatcher dies even though the service is still "started" and no errors were logged (I have an Application Log feature to send messages that can be observed during start up and errors.)
How do I keep the service/application "running" in order to keep the instantiated clsWatcher object alive?
|
|
|
|
|
ToolTimeTabor wrote: and then the service "finalizes" What does that mean? Does the service crash? Is yourservice.exe still in the list of processes in the task manager ("show processes of all users")?
|
|
|
|
|
ToolTimeTabor wrote: How do I keep the service/application "running" Create an infinite loop (and exit if Windows is shutting down). A service doesn't have a loop that keeps the app alive until someone "closes" it, as it should not be closed.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have a very similar windows service that does exactly what you are describing.
Dim watcher As New FileSystemWatcher()
watcher.Path = gsWatcherPath
watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.FileName Or NotifyFilters.DirectoryName)
watcher.Filter = "*.txt"
AddHandler watcher.Created, AddressOf OnChanged
watcher.EnableRaisingEvents = True
Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
Call ProcessFile_Master(e.FullPath)
End Sub
Once you instantiate the FileSystemWatcher, there is nothing else to do, no loops, nothing extra.
The Sub, OnChanged, gets fired for each file that is changed in the "watched" directory.
Hope this helps.
|
|
|
|
|
I am trying to write code for multiple if/and statements, but don’t really know how. Any help would be very much appreciated!
I need the code to loop through these statements and enter the correct information in cell M5.
IF C9= ”SHIP EXACT” AND G13<c13, then="" m5="”ENTER" remake”
if="" c9="”" no="" backorders="" on="" stock="" unless="" zero="" were="" shipped”="" and="" g13<c13,="" remake="" required”
if="" ship="" tolerance”="" g13="" c13="">10%, then M5= “ENTER REMAKE”
IF C9= ”5% Ship Tolerance” AND G13/C13>5%, then M5= “ENTER REMAKE”
|
|
|
|
|
First, phase them in your natural language, such as English:
If I score 90 and above,
then my grade is 'A'
Else If I score 80 and above (but below 90 - this one can be omitted as it would have been considered in the first if statement)
then my grade is 'B'
else If I score 70 and above
then my grade is 'C'
...
Else (last condition no need to have condition, it is understood to be none of the above)
the my grade is 'F'
Finally, print out my grade
Once you are satisfied with these statement, then translate them to vb.net code.
refer: If...Then...Else Statement (Visual Basic)[^]
|
|
|
|
|
You should use
if [condition] then
[result]
else if [condition2] then
[result2]
end if
Since when is being together a prerequisite for being in love with someone?
|
|
|
|