Solved

Using a macro to copy a cell to a field on a web page

Posted on 2011-09-17
7
146 Views
Last Modified: 2012-05-12
Hello,

I would  like to create a macro to copy data from a group of cells to a group of fields on a web page. My company has a web site that we can go to, create a new flyer, input about 15 data fields and then print the flyer to hand out. I have a spread sheet that calculates the data for me. Now I want to copy the data one cell at a time and past it to the web site one field at a time. I created a macro by recording key strokes (ctrl+c alt+tab ctrl+v tab ctrl+c etc...) just the way I would do it manually but it doesn't work. It won't switch over to the web page that I have open. Is there a way to do this?
Thanks,
Tim
0
Comment
Question by:TimJar
  • 4
  • 3
7 Comments
 
LVL 33

Expert Comment

by:Norie
Comment Utility
Tim

One way you can do this by automating IE.

It should be quite straightforward, something like this.

1 Navigate to page.

2 Grab references to the data fields on the page.

3 Put the values from Excel into the data fields

4 Submit the page if required.

The individual steps would need to be refined of course but that's the basics.
0
 

Author Comment

by:TimJar
Comment Utility
How would you do step 2. I can do it manually like this:

1. Select the first field in the page
2. alt+tab to go to the .xls file
3. select the first cell
4. ctrl+c
5. al+tab to go back
6. ctrl+v
7. tab to next field
and so on
0
 
LVL 33

Expert Comment

by:Norie
Comment Utility
It's hard to be specific as it really depends on the page and how it's designed.

It also depends on the data in Excel.

With the approach I'm suggesting there wouldn't be any tabbing/selecting.


0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:TimJar
Comment Utility
I don't know much about automating IE. Can you tell me what I should be researching?
0
 
LVL 33

Expert Comment

by:Norie
Comment Utility
I don't know where you would research it.

If you can post the URL I could probably post some code.
0
 

Author Comment

by:TimJar
Comment Utility
I think you have to be on our VPN to access it but here is the URL

http://www.cgxsolutions.com/idesign/index.asp
0
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
Comment Utility
This is how you could do the login using VBA, it takes the username and password from a worksheet.
Option Explicit

Sub LogIn()
Dim IE As Object
Dim doc As Object
Dim frm As Object
Dim inpUser As Object
Dim inpPword As Object
Dim strURL As String

    strURL = "http://www.cgxsolutions.com/idesign/index.asp"

    Set IE = CreateObject("InternetExplorer.Application")

    With IE

        .navigate strURL

        Do While .Busy: DoEvents: Loop
        Do While .ReadyState <> 4: DoEvents: Loop
        .Visible = True

        Set doc = .document



        With doc

            Set frm = .forms(0)

            Set inpUser = .getelementbyid("frmUser") ' get reference to input for username

            inpUser.Value = Range("B1").Value ' put value from B1 into username

            Set inpPword = .getelementbyid("frmPWord") ' get reference to password input

            inpPword.Value = Range("B2").Value ' use value in B2 for password

        End With

        frm.submit ' now submit the login form

       ' .Quit ' Optional
    End With

End Sub

Open in new window

If you look at the source code of the page you want to fill out you will find the names/ids for the data fields.

Then you can use the same method this code uses to put values from the worksheet in the fields on the page.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now