VBA to Loop Through Files

Anonymous
2013-12-04T07:22:18+00:00

Hi.

I have a series of identical workbooks in a folder in the following location: C:\Users\hughesel\Desktop\Test

I want to create a macro which will open each of the files in turn and select all of the contents on the QPI sheet and paste special values the information (to remove the fomulas.  The QPI sheet is password protected so that would need to be turned off too

  • the password is test

I then want the file to be saved and closed before the macro moves on to the next file in the folder.

I have tried to peice together bits of code myself but with no success.

Is anyone able to help?

Many thanks.

Kind Regards.

Liz.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

10 answers

Sort by: Most helpful
  1. Anonymous
    2013-12-04T12:07:07+00:00

    That seems to work now - thank you so much for your help!

    Was this answer helpful?

    0 comments No comments
  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Anonymous
    2013-12-04T11:11:19+00:00

    I am not sure if there is anything special about it.

    It seems to open the file as when i have clicked debug i can see that the file that is shown when i hover over the strFile is open.

    Would it make a difference that the workbook being open contains its own macros - albeit ones that I dont think need to be enabled in this instance?

    Was this answer helpful?

    0 comments No comments
  4. HansV 460.5K Reputation points MVP Volunteer Moderator
    2013-12-04T11:02:01+00:00

    OK, thanks. That would mean that there is a problem opening one of the workbooks.

    When the macro is paused after clicking Debug, you can hover the mouse pointer over the word strFile in the code. You should see the filename in a popup box. Does that provide a clue - is there anything special about that file?

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2013-12-04T10:56:10+00:00

    that is definitely the line highlighted in yelllow

    Was this answer helpful?

    0 comments No comments