I know that there are tons of versions in JavaScript out there but I need this as a vb version for use in Scripting in Exel 2010? Has anyone done this translation?
If your query is for XML DOM methods, , then in the VB Editor in Tools > References add a reference to Microsoft.MSXML2
goto 1) below!
If your query is for DHTML DOM methods, then in the VB Editor in Tools > References add a reference to Microsoft.mshtml
1) Then you can access the DOM using all the methods that you see in the Object Browser (keystroke f2 in the VB Editor, then select MSHTML in the drop down to select DHMTML DOM Library.
an example using MSXML would be:
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("title")[0]
y=x.childNodes[0]
msgbox y.nodeValue
an example (using MSHTML) would be :
Sub testDoc()
Dim xDoc As MSHTML.HTMLDocument
Dim sURL As String
Dim oElement As MSHTML.HTMLBaseElement
Set xDoc = New MSHTML.HTMLDocument
With xDoc
.Open (sURL)
Set oElement = .getElementById(idName)
MsgBox oElement.ID
End With
End Sub
I hope that gets you started in the right direction.
BTW,
Philip
Related
I'm trying to make a webscraping program in Visual Studio 2019 using VB.Net Framework but I'm running into an issue. I have the below code to locate an open IE window so that I can manipulate it. The issue I'm running into is when I use IE.Document. the list that appears does not show getelementsbyid. Here is a snippet of my code, it's able to find the appropriate IE window and bring it into focus but I need to be able to manipulate the elements on the page.
I have also added the Com References
Microsoft HTML Object Library
Microsoft Internet Control
Dim SWS as new SHDocVw.ShellWindows
Dim IE as SHDocVw.InternetExplorer
For Each IE in SWS
If IE.locationName = "XXXXXXXX" Then Exit For
NExt
'To get focus on IE window
IE.Visible = False
IE.Visible = True
IE.Document.
I would appreciate any insight since I'm at a loss as to why getelementbyid won't show.
As an alternative, you can try to refer to the code example below that may help you to get/ set values.
If you want to set data then refer to the line below.
IE.Document.All.Item("fname").Value = "ABC"
If you want to fetch data then refer to the line below.
Console.WriteLine(IE.Document.All.Item("fname").Value)
I am encountering an
Object doesn't support this property or method
Runtime error in excel vba.
Note : The code works fine in my laptop.This error happened when I migrated the code to my desktop pc.
Below is the UPDATED code.
Dim ie As InternetExplorer
Dim htmldoc As MSHTML.IHTMLDocument
Dim ro1 As MSHTML.IHTMLElementCollection
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False
ie.navigate "url"
Set htmldoc = ie.document
Set ro1 = htmldoc.getElementById("table id").getElementsByTagName("tr")
ThisWorkbook.Sheets(1).Cells(k, j) = rows(k).Children(0).textContent
ro1(k).Children(0).textContent is the error part.
I have checked Tools->References. Microsoft Internet Controls and Microsoft HTML Object Library has been checked.
Can anyone please guide me for this ?
Try using InnerText instead of textContent and see if that works for you.
ThisWorkbook.Sheets(1).Cells(k, j) = rows(k).Children(0).InnerText
Start by adding a line Option Explicit at the top of your module, and then Debug->Compile to identify variables and objects that aren't properly declared or are being misused, Keep compiling until no more warnings.
Also, don't use the word ROWS as an object name. Rows already means something in Excel & VBA.
Here is a list of reserved words that should be avoided. (I realize it's labelled Access 2007 but the list is very similar, and it's surprisingly difficult to find an recent 'official' list for Excel VBA.)
I'm using MS-Access 2010 and Autocad 2012 64bit and work in manufacturing.
I want to be able to at the very least, populate fields in a title block, better still I would like to use data in my access database to write data into a sheet set (the current system works by reading the sheet set values such as sheet title and number into my title block).
The following code is all I have at the moment and it will open autocad and write the date into the command line.
Private Sub OpenAutocad_Click()
Dim CadApp As AcadApplication
Dim CadDoc As AutoCAD.AcadDocument
On Error Resume Next
Set CadApp = GetObject(, "AutoCAD.Application")
If Err.Number <> 0 Then
Set CadApp = CreateObject("AutoCAD.Application")
End If
On Error GoTo 0
CadApp.Visible = True
CadApp.WindowState = acMax
Set CadDoc = CadApp.ActiveDocument
CadDoc.Utility.Prompt "Hello from Access, the time is: " & TheTime
Set CadApp = Nothing
End Sub
I have no idea where to go from here. What are the commands to control the sheet set manager and change data, and can the .dst file be edited without even opening up autocad? is there a list of all available autocad vba commands and functions?
If you are declaring CadApp as AcadApplication you must have added a reference to AutoCAD.
That means you should be able to see the object model using your Object Browser in your VBA IDE. No?
There is also a very helpful site www.theswamp.org which has a whole section devoted to AutoCAD VBA.
If I understand your question correctly, you want to automate filling attributes in a drawing title blocks (such as title, drawer, part number, etc) right from MS Access.
Your code can access the Autocad command line already, but Autocad doesn't seem to have the exact command for filling drawing attribute. (command list)
So looks like you need to fill the attributes programatically using the COM API.
The following question appears to be relevant with yours and the accepted answers does provide a sample code:
Is it possible to edit block attributes in AutoCAD using Autodesk.AutoCAD.Interop?
Note that in that question the asker was developing a standalone application in C# .NET, where as you will be using VB Automation from MS Access. Shouldn't be too different since the Component Object Model (COM) being used is the same.
What are the commands to control the sheet set manager and change data and can the .dst file be edited without even opening up autocad?
(sorry can't post more than 2 links)
docs.autodesk.com/ACD/2010/ENU/AutoCAD%202010%20User%20Documentation/files/WS1a9193826455f5ffa23ce210c4a30acaf-7470.htm
No mention about data change, though.
is there a list of all available autocad vba commands and functions?
Yes.
%ProgramFiles%\Common Files\Autodesk Shared\acad_aag.chm - Developer's Guide
%ProgramFiles%\Common Files\Autodesk Shared\acadauto.chm - Reference Guide
Online version:
help.autodesk.com/cloudhelp/2015/ENU/AutoCAD-ActiveX/files/GUID-36BF58F3-537D-4B59-BEFE-2D0FEF5A4443.htm
help.autodesk.com/cloudhelp/2015/ENU/AutoCAD-ActiveX/files/GUID-5D302758-ED3F-4062-A254-FB57BAB01C44.htm
More references here:
http://usa.autodesk.com/adsk/servlet/index?id=1911627&siteID=123112
:) Half the way gone ;)
If you has a open autocad with a loaded drawing you can access the whole thing directly.
Sub block_set_attribute(blo As AcadBlockReference, tagname, tagvalue)
Dim ATTLIST As Variant
If blo Is Nothing Then Exit Sub
If blo.hasattributes Then
tagname = Trim(UCase(tagname))
ATTLIST = blo.GetAttributes
For i = LBound(ATTLIST) To UBound(ATTLIST)
If UCase(ATTLIST(i).TAGSTRING) = tagname Or UCase(Trim(ATTLIST(i).TAGSTRING)) = tagname & "_001" Then
'On Error Resume Next
ATTLIST(i).textString = "" & tagvalue
Exit Sub
End If
Next
End If
End Sub
Sub findtitleblock(TITLEBLOCKNAME As String, attributename As String,
attributevalue As String)
Dim entity As AcadEntity
Dim block As acadblcck
Dim blockref As AcadBlockReference
For Each block In ThisDrawing.BLOCKS
For Each entity In block
If InStr(LCase(entity.objectname), "blockref") > 0 Then
Set blockref = entity
If blockref.effectivename = TITLEBLOCKNAME Then
Call block_set_attribute(blockref, attributename, attributevalue)
exit for
End If
End If
End If
Next
Next
End Sub
call findtitleblock("HEADER","TITLE","Bridge column AXIS A_A")
So assume you has a title block which has the attribute TITLE then it will set the Attribute to the drawing name. it mioght also possible you has to replace the thisdrawing. with your Caddoc. I usually control Access and Excel form autocad and not vice versa ;)
consider also to use "REGEN" and "ATTSYNC" if "nothing happens"
thisdrawing.sendcommens("_attsync" 6 vblf )
This question already has answers here:
Using standard .Net libraries with VBA
(2 answers)
Closed 9 years ago.
I need to download and save a file automatically from a URI. I think I can use URLDownloadToFile from "urlmon" library but I wanted to use the WebClient.DownloadFile method.
I hoped it would be a cakewalk but for reasons beyond me, I am not able to view or use the members of the WebClient class in the VBA 7 IDE. I have already referenced the .Net 2 framework's System.tlb and am able to see the classes in the System.Net namespace but members for many of the classes are not visible and I cannot use them in my code.
I get a compilation error on trying to use a code like:
Dim Downloader as New System.WebClient
Downloader.DownloadFile("uri","filename")
Maybe I have not registered the .Net classes to be used in VBA and hence the problem but; the System.dll being referred to in my project is located at C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.tlb
which confuses me even more. Also, it will really help if someone can detail out the process to reference .Net Framework libraries in VBA 7.
Thanks in advance!
In lieu of .Net libraries, I suggest using the MSXML library. You can add it to VBA in the IDE by clicking "Tools" ---> "References..." and checking the box next to "Microsoft XML, x.x" where x.x is the most recent version.
Here is a quick test you can run:
Public Sub Downl()
Dim xhttp As MSXML2.XMLHTTP
Set xhttp = New MSXML2.XMLHTTP
Dim oFile As Integer
oFile = FreeFile()
Open CurrentProject.Path & "\test.png" For Binary Access Write As oFile
Dim bdata() As Byte
With xhttp
.Open "GET", "https://www.google.com/images/srpr/logo11w.png", False
.send
bdata = .responseBody
Put oFile, 1, bdata
End With
Close oFile
End Sub
I'm trying to open a doc file under VB.NET, I found a very simple way to do it using word:
For example:
Dim doc As Word.Document
Dim wordApp As New Word.Application
Dim allText As String
Try
doc = wordApp.Documents.Open("C:\marti.doc")
allText = doc.Range.Text()
doc.Close()
RichTextBox1.Text = allText
Catch
'error
End Try
(More detailed info: http://support.microsoft.com/kb/316383)
This could work, but it need to open Microsoft Word window to handle it. I need to use it without Word installed. So I need a Library which can open doc/excel files.
Do you know a good Library that can do this?
I found this library:
http://bytescout.com/download/trial/documentsdk.html
Have you tried this?
The recommended way of interacting with Office files is through the Office OpenXML library. You can get it here.
If you are using Microsoft Office 2003, you can load and save documents in Open XML if you have installed the Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint 2007 File Formats. You can download the compatibility pack and find more info here.
This is an example method to gather the content of the document:
Private Shared Function GetWordDocContent(strDoc As String) As String
Dim stream As Stream = File.Open(strDoc, FileMode.Open)
Dim wordprocessingDocument__1 As WordprocessingDocument = WordprocessingDocument.Open(stream, True)
Dim body As Body = wordprocessingDocument__1.MainDocumentPart.Document.Body
Dim content As String = body.InnerText
wordprocessingDocument__1.Close()
Return content
End Function
Another example here.
for handling docx file you can try NPOI or DocX
for the old word format (.doc) I've tried Syncfusion DocIO components, but i prefer to use word automation with NetOffice, much better than the interop