ActiveSheet.QueryTables.Add Connection:
Jun 13, 2006
Sub WebQuery()
Dim strSearch As String
strSearch = "abc"
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.xyz.com/&=" & strSearch & "", _
Destination:= Range("A1"))
.Name = "search?hl=en&ie=UTF-8&oe=UTF-8&q=" & strSearch & ""
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingAll
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
End Sub...
View 6 Replies
ADVERTISEMENT
May 20, 2003
I recorded setting up a query to get information off our Data Warehouse about a Tracking Number that the user enters into the spreadsheet and got this little piece of gold.
Sub DataDump()
Dim sqlFromText, sqlWhereTxt, sqlSelectTxt
Dim qt As QueryTable
For Each qt In Worksheets("DW Data Dump").QueryTables
qt.Delete
Next qt
On Error GoTo err_Label
The problem is that now when I try to run it I get a general ODBC error and the debugging line that is highlighted is .Refresh BackgroundQuery:=True.
View 9 Replies
View Related
May 30, 2009
I am having problems getting to work a web query in a VBA macro. The goal is simply to get a value retrieved from a web query into an excel cell.
The below code works well with standard html pages (like replacing the url with www.google.com). However, the page I want to retreive (a query at geonames.org that retreives an altitude value for given lattitude/longitude values) does not contain any HTML headers, but just a number in plain text. In this case the below query does not returns anything. I tried different formating options for the query but up to nownothing works.
View 3 Replies
View Related
Jan 11, 2013
I have a Workbook containing two worksheets "X" and "FILES". The worksheet "FILES" contains the name of each file in a directory on my desktop "C:UsersOwnerDesktopDATA-X" in cells (A1:A1000) (There are 1000 files in the folder "DATA-X". The worksheet "X" is a blank worksheet.
The following code loops 1000 times, each time importing the "k"th file from the folder "DATA-X" and storing it in the worksheet "X". After each loop, the worksheet "X" gets replaced with the data in the next file from the folder "DATA-X". As the program is running, it can be seen in the task manager that memory is accumulating in the Excel program. In fact, it cannot finish because it will use up all memory by then (I get a message "OUT OF MEMORY").
VB:
Sub MemoryTest()
Dim qt As QueryTable
Dim WSh As Worksheet
Sheets("X").Select
[Code]....
View 1 Replies
View Related
Jun 23, 2007
I need understanding what is the maximum length of string data type. I read that is 63K characters... but, in my case... maximum value is 253. I don't know why happens this. here is some code from one of my buttons.
Private Sub btn_procesare_Click()
Dim intUnit As Integer
Dim strBuffer As String
Dim contor, var_else, cale, dest, dest_final, masca, filtru, **** As String
Dim vntbuf As Variant
Dim sql As Variant
For i = 0 To Me.ListBox2.ListCount - 1
Application.Worksheets(1). Range("A" & i + 2).Value = Me.ListBox2.List(i, 0)
Next...........................
when watch for x, the value is maximum 253 characters. I get error Data Type Mismatch - Error 13 with this.
View 4 Replies
View Related
Jun 20, 2008
How would I code the Active Sheet to be renamed Sheet1?
View 9 Replies
View Related
Mar 13, 2014
I need to copy a value on an activesheet cell A1, to another workbook located at d:locationaaa.xls cell C3.
View 7 Replies
View Related
Oct 17, 2008
All I want to do is copy the active worksheet to then end of another workbook. I have alread set my variables, here is the line that is causing me a problem: ....
View 10 Replies
View Related
Oct 22, 2008
I have a WorkBook with each sheet being a calendar month. I want to set the ActiveSheet as the current month so each time I open the WorkBook it opens to the current month WorkSheet not the last WorkSheet I was viewing.
View 12 Replies
View Related
Jan 22, 2009
Got a wee problem with some syntax for a copy function. At the moment the code i have copies the range and pastes to another range which is defined by a cell number. But i need it to paste special (values only).
View 5 Replies
View Related
Apr 27, 2009
I have looked at previous posts and found some information about ActiveSheet.Paste errors, which appear to be related to having activate, select and paste functions in the wrong order.
I am still getting an error at the ActiveSheet.Paste point of my code which I cannot seem to overcome, although this same code works on another macro doing exactly the same action...
ChDir _
"\workgroupHighlight_reportingTemplates"
Workbooks.Open Filename:= _
"\workgroupHighlight_reportingTemplatesProgramme report template.xls"
View 9 Replies
View Related
Oct 19, 2009
Group the same cells in each row,
if found, in Column 2 that refer to same cells in Column 1 and sum the cells in col 3 and 4 that refer in column 2.
Col 1
Col 2
Col 3
Col 4 1
272
0125
200
10 2
272
0125
100
5 3
273
203
500
85 4
274 ................
View 9 Replies
View Related
Sep 12, 2006
I wrote a macro on mac office 2004 which work perfectly on my pc but not on my mac.
The macro is very simple
Sub Delete_Next_Sheet()
ActiveSheet.Next.Delete
End Sub
It just delete the next sheet after the activesheet. However on the mac, it doesn´t recognize the Next. It display an alert mesage "Invalid or unqualified reference".
I was woundering if there is another way (as simple and as fast if posible) to get a macro avoiding loop and sheet.count to delete the next sheet after the activesheet.
View 4 Replies
View Related
Jun 7, 2007
I am trying to write a small sub which will make do an "AutoFit" for all columns of the Active Sheet. For example, the code below does an "AutoFit" for columns A:J of a sheet. How can I make it do the same for all columns (not only for columns A:J) of the ActiveSheet?
Columns("A:J").EntireColumn.AutoFit
View 2 Replies
View Related
Oct 15, 2009
I am trying to use ActiveSheet.Name formula to rename the active sheet. It is only working part of the time and I can't figure out why. I do know, however, when it is going to work and when it is not going to work. If cell A2 contains two words, it does not work. If cell A2 contains only one word, it does work. Here is the code. The highlighted part in blue is the code that names the sheet. I have attached sample spreadsheet if needed.
View 4 Replies
View Related
Aug 19, 2013
I've currently got a problem with renaming the ActiveSheet when multiple worksheets are present. The code below, utilizes existing fields on the worksheet and a concat with static text. The code works great if only one sheet is present. However, as soon as the second sheet is inserted in the workbook, I'm now receiving a 1004 error (application-defined or object-defined error).
Code:
Private Sub updateWorksheetName_Click()
Dim fNumber
Dim pCheckNumber
[Code].....
View 9 Replies
View Related
Nov 1, 2007
I have a ComboBox. When a user selects an item from the ComboBox and clicks a command button (Add Button) the selection that the user selected writes to a row in the active worksheet and then resets the ComboBox allowing the user to make another choice after clicking the "Add" command button. I am trying to remember how to write the code for row offset so that when the user makes their next selection from the ComboBox and clicks the "Add" command button it puts it the selection in the next row of the active spreadsheet thus creating a running list of the users choices. Here is a line of the
Private Sub cmbAdd_Click()
ActiveSheet.Cells(2, 3) = cbxSeverity
cbxSeverity.Value = ""
End Sub
After the tcbxSeverity.Value ="" line I was testing trying to get to the next row by using something like this:
Private Sub cmbAdd_Click()
ActiveSheet.Cells(2, 3) = cbxSeverity
cbxSeverity.Value = ""
ActiveCell.Offset(1,0).Select
End Sub
I know that this code is incorrect but I cannot remember how to offset or check Rowsource to move to the next line.
View 2 Replies
View Related
Jun 26, 2008
I am working on transfering some code from 2003 to 2007. I have gotten almost everything to work, but am now having an issue with the way it places the pictures into my spreadsheet.
The code asks the user to select a folder containing .jpg files. It then places each of the .jpg photos onto a single spreadsheet. Each picture is suppose to be placed in a different cell. When I step through the code, the active cell changes correctly based on the offsets, but it always pastes each photo in cell B4. Through some research I have found others to see this problem with ActiveSheet.Pictures.Insert in 2007.
Following is the
Private Sub BatchProcessThumb2x3()
Msg = "Select a file containing the photos you want to insert."
Directory = GetDirectory(Msg)
If Directory = "" Then Exit Sub
If Right(Directory, 1) "" Then Directory = Directory & ""
View 9 Replies
View Related
Oct 13, 2006
how to go about or refer me to how exactly you assign a closed workbook to be active. I know this sounds off and its probably the wrong way to word it so here's my problem. I am developing a macro in Visual Basic 2005 using VB. I have a connection string that looks like this:
Private m_sConn4 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:2005.xls;" & _
"Extended Properties=""Excel 8.0;HDR=YES"""
What I need to do is connect to it and update which I have done successfully, then save it as 2006.xls. Is there some sort of m_sConn4.SaveAs or something of that nature.
View 2 Replies
View Related
Jan 23, 2007
Private Sub Workbook_Open()
'Application. ScreenUpdating = False ' Turns off screen updating
Dim Filename As String
Dim nFam As Integer
Dim cRow As Integer
Dim i As Integer
ws As Worksheet
Filename = "O:BVRMusers_sharedJCIntraday ToolFamily List.xls"
Workbooks.Open Filename 'Opens Family List
'Count the number of rows (Families) in Filename (Family List)
Set ws = ActiveSheet
With ws
. Cells(1, 1).Select
cRow = .UsedRange.Rows.Count
End With
End Sub
i cannot get ws to be set as the ActiveSheet. i receive a run time error 91 each time and cannot figure out what is wrong. i've used this code before under subform functions, but this is the first time i've placed it in the "ThisWorkbook" area.
View 2 Replies
View Related
Oct 30, 2009
I'm trying to "export" data from a static ws "order" (Sheet2) to a selected (active) worksheet. This will happen with 15 different (random) cells.
I got this far but the copying isn't happening from the correct sheet or going to the active sheet. The data in "G5" on "order" should go to the first unused row on the active sheet. What I got was backwards.
Once I get the first one to work I can finish the code for the other 14 cells. I appreciate getting pointed in the right direction
View 6 Replies
View Related
Jul 24, 2006
I have a workbook with 25 sheets containing metric information as part of a performance management model. Fundamental to this is the visual success or failure of each of these 25 sheets which I've highlighted by setting the worksheet tab colour accordingly. The code to achieve this is detailed below. This code is triggered by the Worksheet_Change event at the workbook level and works fine in single user mode. When the workbook is shared however, an error 1004 is generated.
Private Sub Worksheet_Change(ByVal Target As Range)
For Each c In Range("PassFail")
If c.Value = "Fail" Then
ActiveSheet.Tab.ColorIndex = 3
ElseIf c.Value = "Pass" Then
ActiveSheet.Tab.ColorIndex = 4
End If
Next c
End Sub
View 5 Replies
View Related
May 22, 2014
I am looking for a way to autofilter a list in "Sheet2" based on the value in Cell A2 of the ActiveSheet. I have about 20 tabs in a workbook that need to be populated with a monthly sheet that is pasted into "Sheet2" every month.
View 1 Replies
View Related
Jul 18, 2009
to retrieve the data from MS access table in to the DB Grid at user form through MS SQL Query.
I am trying to use ADO for the same.
View 9 Replies
View Related
Jun 8, 2006
i have two workbooks that use a identical worksheet which is called products (this sheet contains rows of over 19000 products ). The problem is i cannot merge the two workbooks together because they are just too big in size.
Also these workbooks have similar userforms and macros that rely on this product databases (worksheets).
My problem is when i add a new product to of one product databases i have to also add it to the second product database again. Is there a way where i can update both worksheets together without opening both workbooks.
I have three userforms that rely on this worksheet from both workbooks:
frmNewProduct - To add a new product to the worksheet.
frmProductUpdate - To edit, replace or delete products in the worksheet.
frmSearch - To search for products inside the worksheet.
I have also got other define names, worksheets and formulas that rely on these product database worksheets.
View 9 Replies
View Related
Sep 7, 2006
I'm trying to connect to SAP R/3, and I think I'm not sure which references (Tools --> References) I'm supposed have checked.
All I want to do for now is the following:
Dim sapConn As Object
Set sapConn = CreateObject("SAP. Functions")
Unfortunately, I am getting a "Run-time error '-2147024770 (8007007e)': Automation error. The specified module could not be found."
I have read somewhere random on the internet that I should add "SAP:Remote Function Call: COM Support 1.0 Type Library" which links to the SAPGui Provided library librfc32.dll. However, this alone doesn't seem to work...
View 5 Replies
View Related
Aug 4, 2014
I was messing around with data connections and importing stuff from a network in real time. Cool stuff. But everytime I open ANY excel worksheet on this computer, it tells me "file cannot be found" and refers to one of the first files I used for this. this happens no matter what workbook I am opening.
When I click data --> connections its empty.
View 2 Replies
View Related
Mar 7, 2007
I have a series of external database connections that I run in Excel, connecting to a Server based DB and running some SELECT statements. (ingres). We may have up to dozen of client machines accessing the ingres DB at any time. All is good at this point but when excel goes to INSERT some calculated data back to the main database, it appears that my Excel spreadsheet connection is locking the database when it connects, keeping other people from using their client connections.
first question: Does anyone know if the connection excel uses to run sql statements via external database connection will indeed prevent other users from connecting to the main database?
second question: if so, is there a setting or something that can make excel more "passive"?
View 9 Replies
View Related
Jul 11, 2014
This file connects to a weather API. The laptop I am using connects through a VPN connection. For some reason whenever I am on the VPN if I try to refresh the information I will get an error and the macro will fault out. Other than that the macro works perfectly fine.
Attached is the file in question : Weather Forecast Spreadsheet Draft V12.xlsm‎
When debugging the error goes to:
How can I place in an error management instead of the code just getting blocked out.
View 1 Replies
View Related
Feb 12, 2009
I have a VBA application that uses data from a sheet in the excel workbook. It accesses this data with an ADO connection. On workbook open I open this connection--I declare it as public variable so I can continue to use it throughout the session. My problem is that the connection really doesn't ever dissappear. I have the problem that once I close the workbook, the project still exists in the VB Editor. How do I get rid of the connection? I am stuck because I declared it as public? I want to keep it open, rather than opening every time I want to use it, because it is faster to keep the connection open.
My code is below.
Option Explicit 'requires variable declaration
'declare global connection
Public cn As ADODB.Connection
Sub OpenDBConnection()
'open db connection
'this happens on workbook open
If cn Is Nothing Then
Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & WCHSBook.FullName & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"""
.Open
End With
End If
End Sub
View 9 Replies
View Related