I am trying to covert spread sheet with hundreds of image path to html pages. For example:
excel sheet
imageId imagePath
1 images/ima1
2 images/ima2
3 images/ima3
... .........
... ........
Are there faster ways to covert these images to html files instead of typing them 1 by 1?
The html files I need is like the following:
<img src=images/ima1 title='ima1' />
<img src=images/ima2 title='ima2' />
<img src=images/ima3 title='ima3' />
Thanks for the help.
There are several ways you can do what you want.
1 . On another sheet, create a formula that will take the information from the first sheet and produce the HTML you want.
="<img src=" & CHAR(34) & INDIRECT("Sheet1!B" &ROW()) & CHAR(34) & " title=" & CHAR(34) & INDIRECT("Sheet1!A" & ROW()) & " />"
Assuming your data is on Sheet1, every row on your second sheet (with that formula in) will contain the html of the same row on Sheet1. (You'd need to adjust the sheet name and columns if there not the same)
Doing this you can then copy and paste everything from the 2nd sheet.
2 . Using a macro to generate the file.
Public Sub GenerateHTML()
Dim Handle As Integer
Dim Sheet As Worksheet
Dim Row As Integer
Set Sheet = ThisWorkbook.ActiveSheet
Row = 2
Handle = FreeFile()
Open "output.html" For Output As Handle
Print #Handle, "<html>" & vbNewLine & "<head>" & vbNewLine & "<title>My Gallery...</title>" & vbNewLine & "</head>" & vbNewLine & "<body>"
Do
If Sheet.Cells(Row, 1) = "" Then
Exit Do
Else
Print #Handle, "<img src=" & Chr(34) & Sheet.Cells(Row, 2) & Chr(34) & " title=" & Chr(34) & "ima" & Sheet.Cells(Row, 1) & Chr(34) & "/>"
Row = Row + 1
End If
Loop
Print #Handle, "</body>" & vbNewLine & "</html>"
Close #Handle
End Sub
This example will create a html file in the same directory as the spreadsheet containing all the links. You'd need to adjust it to suit your needs as its probably not quite right.
I would create a formula in the next column. Assuming that images/ima1 is in B2 this would be something you could put into C2 to get you what you're after and then paste the formula down.
="<img src="&B2&" title='"&RIGHT(B2,LEN(B2)-4)&"' />"
Related
This is how I am constructing my JSON array to be sent via the PUT method where I am taking some cell value from excel:
body = "{""note"":""" & Cells(RowNote, 3).Value & """,""uniqueIdentifier:""" & Cells(RowNote, 2).Value & ",""IdentifierType"":""ACCOUNT_ID"",""CustomerId"":" & userID & "}"
However i got an error 13 mismatch.
This is an example of the JSON string that can be PUT correctly:
{"note":"call again", "uniqueIdentifier":1716, IdentifierType":"ACCOUNT_ID", "CustomerId":927560}
What should be corrected within the brackets?
Try body = "{""note"":""" & Cells(RowNote, 3).Value & """,""uniqueIdentifier"":" & Cells(RowNote, 2).Value & ",""IdentifierType"":""ACCOUNT_ID"",""CustomerId"":" & UserId & "}" if you do not want " around your integers.
I am trying to append a CSV's last row and allow it to be read by a C# user control.
The reason we have to do that way is because the data become available at two different times.
It works fine except for the following:
It generates an empty line after appending.
After repeating it for 3-4 steps it deletes the whole file.
The code is below:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile = objFSO.OpenTextFile("R:\cat3_data.csv", 1)
strContents = objInFile.ReadAll
objInFile.Close
arrRows = Split(strContents, vbNewLine)
MsgBox UBound(arrRows)
arrRows(UBound(arrRows) - 1) = arrRows(UBound(arrRows) - 1) & "," & "Hi" & _
"," & "Hi" & "," & "Hi" & "," & "Hi" & "," & "Hi"
strContents = Join(arrRows, vbNewLine)
Set objOutFile = objFSO.OpenTextFile("R:\cat3_data.csv", 2)
objOutFile.WriteLine strContents
objOutFile.Close
Set objFSO = Nothing
Trying to apply 2 filters at the same time to a subform.
Want to see records between DATES X and Y, and from BRANCH Z only.
Working fine alone, but can't use both at the same time. I know it's something
Current code:
Private Sub Command39_Click()
If IsNull(Me.txtFrom) Or IsNull(Me.txtTo) Then
MsgBox "Insert date!"
Else
With Me.frmDailyRevenue.Form
.Filter = "[DateDbl] BETWEEN " & Me.txtFromDbl & " AND " & Me.txtToDbl & "" And [F5] = " & Me.cboBranch & """
.FilterOn = True
End With
End If
End Sub
This is basically bits of code I got from the web as I'm really new to this.
So, all advice is welcome.
Try this:
.Filter = "[DateDbl] BETWEEN #" & Format(Me.txtFromDbl,"mm\/dd\/yyyy") & _
"# AND #" & Format(Me.txtToDbl,"mm\/dd\/yyyy") & "# And [F5] = '" & Me.cboBranch & "'"
I supposed that Me.cboBranch is text. If this field contains code, remove single quotes.
Also I noticed that controls you check and controls you take data from are different (Me.txtFrom and Me.txtFromDbl, Me.txtTo and Me.txtToDbl), check this.
Found the problem.
Using BETWEEN and AND for the date range was causing some conflict with the second AND to add the filter for field F5.
So I switched to use >= and <= as follows:
.Filter = "[DateDbl] >= " & Me.txtFromDbl & " AND [DateDbl] <= " & Me.txtToDbl & " AND [F5] = " & Me.cboBranch & ""
Just to clarify, for people that might come for this later, you should use # as Sergey pointed out if you have a date field, my date is in double format, so I don`t need to.
Thanks,
I am currently writing code in VBA to automate a process that sends out an e-mail that contains a table with information generated by a query in an Access database. I am using HTML to format the table in that e-mail, and I need the colors of the rows in that table to alternate colors (odd rows: #ccffcc; even rows: #ffffff), but I cannot seem to figure it out. I have tried to use the child selector, but I cannot see to figure out to get that to work in here. I do not have much experience or knowledge related to CSS or HTML, so I very well could have been using the child selector incorrectly.
Here is what I currently have:
Bodytext2 = "<html>" & _
"<body>" & _
"<TABLE BORDER=0 CELLpadding=0 style='font-family:Arial; font-size:12px'>" & _
"<TBODY>" & _
"<TH bgcolor='#dcdcdc'> Field1 </TH>" & _
"<TH bgcolor='#dcdcdc'> Field2 </TH>" & _
"<TH bgcolor='#dcdcdc'> Field3 </TH>"
'Creates the table
Set rst = mydb.OpenRecordset("Query In Access")
Do Until rst.EOF
Bodytext2 = Bodytext2 & _
"<TR ALIGN=CENTER VALIGN=MIDDLE>" & _
"<TD> " & rst![Field1] & _
"<TD> " & rst![Field2] & _
"<TD> " & rst![Field3]
rst.MoveNext
Loop
rst.Close
Bodytext2 = Bodytext2 & "</table>"
This code produces the correct table with the correct information. however, I am not sure where to add in the code to change the colors of the table's rows, or how to even write the code to do that. My guess so far is that it would be in the "TR Align=center valign=middle" portion, but that is just my guess.
I have looked a lot of other answers on here, but I think that my lack of knowledge in this field is making it difficult for me to determine what I actually need and where it needs to go. So, if there are helpful answers to similar questions that y'all could direct me to, I would greatly appreciate that too.
Thank You!
Create a counter variable before you go into your loop that will let you keep track of your row number, like this:
i = 1
Do Until rst.EOF
If i Mod 2 = 0 Then
Bodytext2 = Bodytext2 & "<TR ALIGN=CENTER VALIGN=MIDDLE BGCOLOR='#ffffff'>"
Else
Bodytext2 = Bodytext2 & "<TR ALIGN=CENTER VALIGN=MIDDLE BGCOLOR='#ccffcc'>"
End If
Bodytext2 = Bodytext2 & _
"<TD> " & rst![Field1] & _
"<TD> " & rst![Field2] & _
"<TD> " & rst![Field3]
rst.MoveNext
i = i + 1
Loop
My apologies for any syntax errors. My VBA is a little rusty.
I'm using VBScript to parse CSV data and display it on a table. I've got the CSV set up and when I open it in Sublime Text, the headers and content are on different lines (there's only one row of content besides the header). It shows two lines in Sublime Text.
The headers don't have a comma at the end of the row so it doesn't break it up and just basically appends the first entry of the second line on to the last entry of the headers line because it's not technically divided by a comma.
The code I'm using is:
<html>
<head>
</head>
<body>
<%#language="vbscript"%>
<table border="1">
<%
dim csv_to_read, fso, act
csv_to_read="sample.csv"
set fso = createobject("scripting.filesystemobject")
set act = fso.opentextfile(server.mappath(csv_to_read))
'Read the first line of the csv, typically these are colum headings
Response.Write "<tr><th>" & replace(act.readline,",","</th><th>") & "</th></tr>" & vbCrLf
'Read the rest of the csv
Response.Write "<tr><td>" & replace(replace(act.readall,vbCrLf,"</td></tr>"&vbCrLf&"<tr><td>"),",","</td><td>") & "</td></tr>"
%>
<caption>Total Number of Records: <%=act.Line-1%></caption>
</table>
</body>
</html>
Why is it not recognizing the line break?
Thanks for your help!
I think your problem is caused by the file not having a EOL marker of vbCrLf (but crLf probably). Evidence:
s = "1,2,3" & vbLf & "4,5,6"
h = "<tr><td>" & replace(replace(s,vbCrLf,"</td></tr>" & vbCrLf & "<tr><td>"),",","</td><td>") & "</td></tr>"
WScript.Echo "vbLf"
WScript.Echo h
s = "1,2,3" & vbCrLf & "4,5,6"
h = "<tr><td>" & replace(replace(s,vbCrLf,"</td></tr>" & vbCrLf & "<tr><td>"),",","</td><td>") & "</td></tr>"
WScript.Echo "vbCrLf"
WScript.Echo h
output:
cscript 23072652.vbs
vbLf
<tr><td>1</td><td>2</td><td>3
4</td><td>5</td><td>6</td></tr>
vbCrLf
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
(I hope that the output will prove to the looping advocates that the double replace produces valid HTML)
Update wrt comment:
This version of the script:
s = "1,2,3" & vbCrLf & "4,5,6"
WScript.Echo ".ReadAll() (faked):"
WScript.Echo s
' h = "<tr><td>" & replace(replace(s,vbCrLf,"</td></tr>" & vbCrLf & "<tr><td>"),",","</td><td>") & "</td></tr>"
' step by step
h = replace(s,vbCrLf,"</td></tr>" & vbCrLf & "<tr><td>")
WScript.Echo "step 1 - EOL handling:"
WScript.Echo h
h = replace(h,",","</td><td>")
WScript.Echo "step 2 - comma handling:"
WScript.Echo h
h = "<tr><td>" & h & "</td></tr>"
WScript.Echo "step 3 - head & tail I:"
WScript.Echo h
h = "<!DOCTYPE html><html><head><title>replace demo</title></head><body><table>" & vbCrLf & h & vbCrLf & "</table></body></html>"
WScript.Echo "step 4 - head & tail II:"
WScript.Echo h
output:
cscript 23072652.vbs
.ReadAll() (faked):
1,2,3
4,5,6
step 1 - EOL handling:
1,2,3</td></tr>
<tr><td>4,5,6
step 2 - comma handling:
1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6
step 3 - head & tail I:
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
step 4 - head & tail II:
<!DOCTYPE html><html><head><title>replace demo</title></head><body><table>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
</table></body></html>
should make visible how the double replace works and that all parts are important.
Just a quick glance and it looks like you're writing out malformed HTML.
Response.Write "<tr><td>" & replace(replace(act.readall,vbCrLf,"</td></tr>"&vbCrLf&"<tr><td>"),",","</td><td>") & "</td></tr>"
I read the inner replace as replace every carriage return with a closing table cell/table row
The outer replace is replacing the commas with a closing cell/opening cell
You're then appending another closing cell/closing row.
In my opinion, looping through rows, whether or not is more performance efficient is easier to read and debug down the road. If this applies to your situation please consider something like these:
Reading csv file in classic asp. Problem: column values are truncated up to 300 characters
How to read CSV files line by line in VBScript