I am trying to use VBA to click on a Java script button on the following website: http://www.ura.gov.sg/realEstateIIWeb/transaction/search.action
I'm trying to get the vba to select a project and then click on the button labelled Add and then the button labelled search in the web link above.
I have managed to get the VBA to open the website and select the project, but some how I am unable to get the VBA to click on the "Add" button and "Search" button
Sub DLDATA()
Dim MAS As Object
Dim STYR As Object
Dim DLD As Object
Dim XLD As Object
Dim form As Variant, button As Variant
Set MAS = CreateObject("InternetExplorer.application")
With MAS
.Visible = True
.Navigate Sheets("Property Value").Range("B30").Value ' Navigate to website
Do Until .ReadyState = 4
DoEvents
Loop
Set STYR = MAS.Document.all.Item("projectNameList")
STYR.Value = Sheets("Property Value").Range("A1").Value ' Select name of property based on name in cell A1.
Set XLD = MAS.Document.all.Item("addOpt")
XLD.Value = Sheets("Property Value").Range("A1").Value
End With
End Sub
this works for me
Sub test()
URL = "http://www.ura.gov.sg/realEstateIIWeb/transaction/search.action"
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate URL
Do Until (ie.readyState = 4 And Not ie.Busy)
DoEvents
Loop
Set STYR = ie.Document.all.Item("projectNameList")
STYR.Value = Sheets("Property Value").Range("A1").Value ' Select name of property based on name in cell A1.
Set Results = ie.Document.getElementsByTagName("input") ' find and click the "add" button
For Each itm In Results
If InStr(1, itm.outerhtml, "addOpt", vbTextCompare) > 0 Then
itm.Click
Exit For
End If
Next
ie.Document.getElementByID("searchForm_0").Click ' click the "search" button
Do Until (ie.readyState = 4 And Not ie.Busy)
DoEvents
Loop
' do whatever
End Sub
Related
So I have this macro, which can copy a single table from an Excel sheet to a template Word document. How do I modify it, so it can copy let's say 6 tables from 6 different Excel sheets into a template Word document? Or can I achieve this with Apache POI API to copy multiple tables from Excel to Word??
Sub ExportDataToWord()
Worksheets("Val Balance Sheet").Range("A1:D22").Copy
Dim wdapp, wddoc As Object
Dim strdocname As String
On Error Resume Next
Set wdapp = GetObject(, "Word.Application")
If Err.Number = 429 Then
Err.Clear
Set wdapp = CreateObject("Word.Application")
End If
wdapp.Visible = True
strdocname = "C:\Users\ako\report.docx"
If Dir(strdocname) = "" Then
MsgBox "The file " & strdocname & vbCrLf & "was not found " & vbCrLf & "C:\Users\ako\.", vbExclamation, "The document does not exist."
Exit Sub
End If
wdapp.Activate
Set wddoc = wdapp.documents.Open(strdocname)
If wddoc Is Nothing Then Set wddoc = wdapp.DocumentOpen(strdocnme)
wddoc.Activate
wddoc.Range.Paste
wddoc.Save
wdapp.Quit
Set wddoc = Nothing
Set wdapp = Nothing
Application.CutCopyMode = False
End Sub
Heres an update to what I was now trying, but it is only pasting the second table into word Template? What needs to be modified here to allow it to paste the multiple words without overwriting the first table.
Sub ExportToWord()
Worksheets("Val Balance Sheet").Range("A1:D22").Copy
Dim wdapp, wddoc As Object
Dim strdocname As String
On Error Resume Next
Set wdapp = GetObject(, "Word.Application")
If Err.Number = 429 Then Err.Clear
Set wdapp = CreateObject("Word.Application")
End If
wdapp.Visible = True
strdocname = "C:\Users\ako\report.docx"
If Dir(strdocname) = "" Then
MsgBox "The file " & strdocname & vbCrLf & "was not found " & vbCrLf & "C:\Users\ako\.", vbExclamation, "The document does not exist."
Exit Sub
End If
wdapp.Activate
Set wddoc = wdapp.documents.Open(strdocname)
If wddoc Is Nothing Then Set wddoc = wdapp.DocumentOpen(strdocnme)
wddoc.Activate
wddoc.Range.Paste
Worksheets("Template Gains and Losses").Range("A1:C11").Copy
Dim wdapp2, wddoc2 As Object
Dim strdocname2 As String
On Error Resume Next
Set wdapp2 = GetObject(, "Word.Application")
If Err.Number = 429 Then
Err.Clear
Set wdapp2 = CreateObject("Word.Application")
End If
wdapp2.Visible = True
strdocname2 = "C:\Users\ako\report.docx"
If Dir(strdocname2) = "" Then
MsgBox "The file " & strdocname2 & vbCrLf & "was not found " & vbCrLf & "C:\Users\ako\.", vbExclamation, "The document does not exist."
Exit Sub
End If
wdapp2.Activate
Set wddoc2 = wdapp.documents.Open(strdocname)
If wddoc2 Is Nothing Then Set wddoc2 = wdapp2.DocumentOpen(strdocnme2)
wddoc2.Activate
wddoc2.Range.Paste
wddoc.Save
wdapp.Quit
Set wddoc = Nothing
Set wdapp = Nothing
Application.CutCopyMode = False
End Sub
I have set up label printing from our app using the b-PAC Android SDK (Java). Using the code below I can replace the text from my template with what I want.
// Start creating P-touch Template command print data
Boolean val= myPrinter.startPTTPrint(6, null);
Log.i("print", "startPTTPrint "+val);
// Replace text
myPrinter.replaceText("abcde");
// Trasmit P-touch Template command print data
PrinterStatus status=myPrinter.flushPTTPrint();
I am now trying to replace an image object within the template. I know it can be done in VBScript using:
bpac.Object ob = doc.GetObject("Photo");
ob.SetData(0, #"C:\Photo\635466380534236711.png", 4);
I can't find any Java examples of this within the b-PAC 3.1 SDK help guide and I have only just began coding in Java so I am very much a novice.
Does anyone have experience with the Brother SDK/Java who can point me in the right direction?
Thanks!
I got this working
Basically I have a template that I copy to an new file on which I make the changes
The image object in the template is called imgPart, the other objects are textblocks
Dim m_partNum As String = "12345"
Dim m_PartName As String = "Plate Special 1 x 2" & vbCrLf & "4 Studs"
Dim m_PartImage As String = "c:\Danny\myLego\Labels\PartImages\3033.png"
Dim m_template As String = "c:\Danny\myLego\Templates\PRINTME.lbx"
Dim m_target As String = "c:\Danny\myLego\Templates\" & m_partNum & ".lbx"
Dim doc As bpac.DocumentClass = New bpac.DocumentClass
Try
File.Copy(m_template, m_target, vbTrue)
If doc.Open(m_target) <> False Then
doc.GetObject("imgPart").SetData(0, m_PartImage, 4)
doc.GetObject("txtPartName").Text = m_PartName
doc.GetObject("txtPartNum").Text = m_partNum
doc.Save()
doc.Close()
Else
MsgBox("Open Error on Receipt with error")
End If
Catch ex As Exception
MsgBox("Error occurred : " & ex.ToString)
End Try
Backgroud:
Use Java + BIRT to generate report.
Generate report in viewer and allow user to choose to export it to different format (pdf, xls, word...).
All program are in "Layout", no program in "Master Page".
Have 1 "Data Set". The fields in "Layout" refer to this DS.
There is Group in "Layout", gropu by one field.
In "Group Header", I create one cell to use as page number. "Page : MyPageNumber".
"MyPageNumber" is a field I define which would +1 in Group Header.
Problem:
When I use 1st method to generate report, "MyPageNumber" could not show correctly. Because group header only load one time for each group. It would always show 1.
Question:
As I know there is "restart page number in group" in Crystal report. How to restart page in BIRT?
I want to show data of different group in 1 report file, and the page number start from 1 for each group.
You can do it with BIRT reports using page variables. For example:
Add 2 page variables... Group_page, Group_name.
Add 1 report variable... Group_total_page.
In the report beforeFactory add the script:
prevGroupKey = "";
groupPageNumber = 1;
reportContext.setGlobalVariable("gGROUP_NAME", "");
reportContext.setGlobalVariable("gGROUP_PAGE", 1);
In the report onPageEnd add the script:
var groupKey = currGroup;
var prevGroupKey = reportContext.getGlobalVariable("gGROUP_NAME");
var groupPageNumber = reportContext.getGlobalVariable("gGROUP_PAGE");
if( prevGroupKey == null ){
prevGroupKey = "";
}
if (prevGroupKey == groupKey)
{
if (groupPageNumber != null)
{
groupPageNumber = parseInt(groupPageNumber) + 1;
}
else {
groupPageNumber = 1;
}
}
else {
groupPageNumber = 1;
prevGroupKey = groupKey;
}
reportContext.setPageVariable("GROUP_NAME", groupKey);
reportContext.setPageVariable("GROUP_PAGE", groupPageNumber);
reportContext.setGlobalVariable("gGROUP_NAME", groupKey);
reportContext.setGlobalVariable("gGROUP_PAGE", groupPageNumber);
var groupTotalPage = reportContext.getPageVariable("GROUP_TOTAL_PAGE");
if (groupTotalPage == null)
{
groupTotalPage = new java.util.HashMap();
reportContext.setPageVariable("GROUP_TOTAL_PAGE", groupTotalPage);
}
groupTotalPage.put(groupKey, groupPageNumber);
In a master page onRender script add the following script:
var totalPage = reportContext.getPageVariable("GROUP_TOTAL_PAGE");
var groupName = reportContext.getPageVariable("GROUP_NAME");
if (totalPage != null)
{
this.text = java.lang.Integer.toString(totalPage.get(groupName));
}
In the table group header onCreate event, add the following script, replacing 'COUNTRY' with the name of the column that you are grouping on:
currGroup = this.getRowData().getColumnValue("COUNTRY");
In the master page add a grid to the header or footer and add an autotext variable for Group_page and Group_total_page. Optionally add the page variable for the Group_name as well.
Check out these links for more information about BIRT page variables:
https://books.google.ch/books?id=aIjZ4FYJOQkC&pg=PA85&lpg=PA85&dq=birt+change+autotext&source=bl&ots=K0nCmF2hrD&sig=CBOr_otRW0B72sZoFS7LC_1Mrz4&hl=en&sa=X&ei=ZKNAVcnuLYLHsAXRmIHoCw&ved=0CEoQ6AEwBQ#v=onepage&q=birt%20change%20autotext&f=false
https://www.youtube.com/watch?v=lw_k1qHY_gU
http://www.eclipse.org/birt/phoenix/project/notable2.5.php#jump_4
https://bugs.eclipse.org/bugs/show_bug.cgi?id=316173
http://www.eclipse.org/forums/index.php/t/575172/
Alas, this is not supported with BIRT.
That's probably not the answer you've hoped for, but it's the truth.
This is one of the very few aspects where BIRT is way behind other report generator tools.
However, depending on how you have BIRT integrated into your environment, a workaround approach is possible for PDF export that we use in our solution with great success.
The idea is to let BIRT generate a PDF outline based on the grouping.
And the BIRT report creates information in the ReportContext about where and how it wants the page numbers to be displayed.
After BIRT generated the PDF, a custom PDFPostProcessor uses the PDF outline and the information from the ReportContext to add the page numbers with iText.
If this work-around is viable for you, feel free to contact me.
I am using Web driver 2.31 with Java. It seems the web driver is unable to perform click action on an input element having onclick() attribute.
The input element I need to perform click action on is having the following attributes - id (which is a random generated number), class, type=button, onclick, onmouseout, onmouseover, title and value.
I'm able to fetch the values of title and value attributes which means that the web driver is able to recognize the input element but is not able to perform click action on it.
I have tried with the following:
webdriver.findElement(By.xpath("xpath for the input")).click()
webdriver.findElement(By.xpath("xpath for the input")).sendKeys(Keys.ENTER);
new Actions(webdriver).moveToElement(webdriver.findElement(By.xpath("xpath for the input"))).click().perform();
None of the above options are working.
Do you get any exceptions from element.click()? It it enabled and visible? One of the problems we had was that WebDriver didn't handle position:static elements correctly, so during playback it would cover the button (and you won't see it on screenshot) and it would throw exception "Element is not clickable at point".
We had similar problem with element and had following code that did work sometimes (but also not 100% of times):
element.click();
if("button".equals(tagName)) {
if(element.isEnabled() && element.isDisplayed())
element.sendKeys(Keys.ENTER);
}
But the problem disappeared itself after upgrading WebDriver and we removed sendKeys(ENTER), also it was working fine in 2.29.0.
I faced exactly same problem in my project. The issue was not to locate the element but the onClick() event was not firing.
Then i found out that something else was there which stopped from the event to fire. I had used java script to enable the date picker box & did this,
((JavascriptExecutor)driver).executeScript ("document.getElementById('txtOriginDate').removeAttribute('readonly',0);");
WebElement originDateBox= driver.findElement(By.xpath(prop.getProperty("originDateBox")));
originDateBox.clear();
originDateBox.sendKeys("9-Dec-2014"); //Enter date
Developer designed this in such a way that if you don't use date picker to select date, a specific variable was not set. Which eventually made the **onclick event not to fire.
The date picker code was something like this,
var jsoncustdate = "";
var jsonorigindate = "";
function onSelectCalender( StrDt, obj )
{
if ( !varReadonly ) {
if ( $( "#txtCustDescisionDate" ).attr( "IsDisable" ) == "FALSE" )
{
if ( obj.id == "txtCustDescisionDate" )
{
custobjDt = new Date( obj.selectedYear, obj.selectedMonth,obj.selectedDay, 0, 0, 0, 0 );
jsoncustdate = custobjDt.getTime();
jsoncustdate = "\/Date(" + jsoncustdate + ")\/";
DisabledBtnStage();
// $("#txtFromDate").datepicker("option", "maxDate", objDt);
}
if ( obj.id == "txtOriginDate" )
{
var objDt = new Date( obj.selectedYear, obj.selectedMonth,obj.selectedDay,0, 0,0,0 );
jsonorigindate = objDt.getTime();
jsonorigindate = "\/Date(" + jsonorigindate + ")\/";
DisabledBtnStage();
// $("#txtToDate").datepicker("option", "minDate", objDt);
}
}
elogCommon.CheckMandatory();
}
}
I finally used date picker in normal way & the event fired smoothly.
I hope this answer will help . .cheers !!!
I have a window that displays my tweets in a label.
My tweets come from my FB page statuses and if i have put a pic or write more than 140 characters then i get a link in tweet to the actuall post.
I wonder if there is any way to get the label text to split so i can point the link into an url to open in webview
This is how far i have got:
var win = Ti.UI.currentWindow;
win.showNavBar();
var desc = Ti.UI.createLabel({
text: win.data,
font:{
fontSize:'20dp',
fontWeight:'bold'
},
height:'300dp',
left:'5dp',
top:'10dp',
color:'#111',
touchEnabled:true
});
win.add(desc);
desc.addEventListener('click',function(e){
var v = desc.text;
if(v.indexOf('http') != -1){
// open new window with webview
var tubeWindow = Ti.UI.createWindow({
modal: true,
barColor: '#050505',
backgroundColor: '#050505'
});
var linkview = Ti.UI.createWebView({
url: e.v,
barColor: '#050505',
backgroundColor: '#050505'
});
// Create a button to close the modal window
var close_modal = Titanium.UI.createButton({title:'Stäng'});
tubeWindow.rightNavButton = close_modal;
// Handle close_modal event
close_modal.addEventListener('click', function() {
tubeWindow.close();
});
tubeWindow.add(linkview);
tubeWindow.open({
modalTransitionStyle: Ti.UI.iPhone.MODAL_TRANSITION_STYLE_FLIP_HORIZONTAL,
});
}
});
win.open();
What i´ve been told i need to split the win.data to get the link. (win.data is the tweet)
now i just have: url: e.v, i need to get the link out
Any ideas on how this can work?
Thanx
//R
I did a similar thing a while ago. pull down the tweet(s) run the text through a regular expression to pull out a URL.
What I did was put each tweet in a tableview row, and set the tableview row to hasChild=true if the regular expression returned anything, then onClick of a tableView row, if hasChild == true open a webview with the given URL (stored in the row).
A regualr expression like the one here should work:
http://www.geekzilla.co.uk/view2D3B0109-C1B2-4B4E-BFFD-E8088CBC85FD.htm
So something like:
str= <<tweet text>>;
re= <<URL expression>>;
check=str.match(re);
now check contains either null or a url.