Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9312607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:40:13+00:00 2026-06-19T01:40:13+00:00

Recently I started getting the error 1004: PasteSpecial method of Range class failed .

  • 0

Recently I started getting the error 1004: PasteSpecial method of Range class failed. I know people have said before that it might be that it is trying to paste to the active sheet when there is none, however, as you can see, everything is based on ThisWorkbook so that shouldn’t be the problem. It happens extra much when Excel doesn’t have the focus.

'references the Microsoft Forms Object Library
Sub SetGlobals()
    Set hwb = ThisWorkbook' home workbook
    Set mws = hwb.Worksheets("Code Numbers") ' main worksheet
    Set hws = hwb.Worksheets("Sheet3") ' home worksheet (Scratch pad)
    Set sws = hwb.Worksheets("Status") ' Status sheet
    Set aws = hwb.Worksheets("Addresses") ' Addresses sheet
End Sub
Sub Import()

    Call SetGlobals
    hws.Select
    'a bunch of code to do other stuff here.
    For Each itm In itms
        Set mitm = itm
        body = Replace(mitm.HTMLBody, "<img border=""0"" src=""http://www.simplevoicecenter.com/images/svc_st_logo.jpg"">", "")
        Call Buf.SetText(body)
        Call Buf.PutInClipboard
        Call hws.Cells(k, 1).Select
        Call hws.Cells(k, 1).PasteSpecial

        For Each shape In hws.Shapes
            shape.Delete
        Next shape

        'Some code to set the value of k 
        'and do a bunch of other stuff.
    Next itm
End Sub

Update: mitm and itm have two different types, so I did it for intellisense and who knows what else. This code takes a list of emails and pastes them into excel so that excel parses the html (which contains tables) and pastes it directly into excel. Thus the data goes directly into the sheet and I can sort it and parse it and whatever else I want.

I guess I’m basically asking for anyone who knows another way to do this besides putting it in an html file to post it. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T01:40:14+00:00Added an answer on June 19, 2026 at 1:40 am

    This probably will not exactly answer your problem – but I noticed a few things in your source code that are too long to place in a comment, so here it is. Some of it is certainly because you omitted it for the example, but I’ll mention it anyway, just in case:

    • Use Option Explicit – this will avoid a lot of errors as it forces you to declare every variable
    • Call SetGlobals can be simplified to SetGlobals – same for Call Buf.SetText(body) = Bof.SetText Body, etc.
    • No need to ‘.Select’ anything – your accessing everything directly through the worksheet/range/shape objects (which is best practice), so don’t select (hws.Select, hws.Cells(k,1).Select)
    • Why Set mitm = itm? mitm will therefore be the same object as itm – so you can simply use itm
    • You’re deleteing all shapes in hwsmultiple times – for each element in itms. However, once is enough, so move the delete loop outside of the For Each loop
    • Instead of putting something in the clipboard and then pasting it to a cell, just assign it directly: hws.Cells(k, 1).Value = body – this should solve your error!
    • Instead of using global variables for worksheets that you assign in ‘SetGlobals’, simply use the sheet objects provided by Excel natively: If you look at the right window in the VBE with the project tree, you see worksheet nodes Sheet1 (sheetname), Sheet2 (sheetname), etc.. You can rename these objects – go to their properties (F4) and change it to meaningful names – or your current names (hwb, mws, …) if you want. Then you can access them throughout your code without any assignment! And it’ll work later, even if you change the name of Sheet3to something meaningful! 😉

    Thus, taking it all into account, I end up with the following code, doing the same thing:

    Option Explicit
    
    Sub Import()
    
        'a bunch of code to do other stuff here.
    
        For Each shape In hws.Shapes
            shape.Delete
        Next shape
    
        For Each itm In itms
            Call hws.Cells(k, 1) = Replace(itm.HTMLBody, "<img border=""0"" src=""http://www.simplevoicecenter.com/images/svc_st_logo.jpg"">", "")
    
            'Some code to set the value of k 
            'and do a bunch of other stuff.
        Next itm
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started getting this error while posting to facebook newsfeed stream of
Recently I've switched to Ninject 2.0 release and started getting the following error: Error
I have a client website where I recently started getting compilation errors: CS0029: Cannot
I recently started getting this error while running gems or bundler. The only thing
I recently migrated to new version of protobuf-net, and i started getting this error
We recently started getting the following error message in TFS 2010 automatedd builds: C:\Builds\1\MyProject\MyProject
I recently started learning about developing in android and now I'm getting an error
Recently I have started getting mySQL too many connection errors at times of high
I recently started getting a javascript error when I go to the Facebook login
Recently two users in our system started getting this error when trying to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.