Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 05-28-2024, 06:36 AM
Guessed's Avatar
Guessed Guessed is offline Copy/Paste of unmodified VBA Code in Word returns an error Windows 10 Copy/Paste of unmodified VBA Code in Word returns an error Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You are asking AI to create code and it pretends it knows what it is doing but I can tell you, in this case it really doesn't. I don't recognise the .DefaultSorting command and it absolutely doesn't belong there (what would you expect to happen if you sorted a single thing? what would it go in front or behind of?). If you removed that line AND the subsequent one then I would expect the code to actually have a chance to work without the error you are seeing.

The CleanText function would also need to be edited to actually do something useful. Looking at how the code is calling CleanText, the intention is to return a valid Bookmark name. I don't know the comprehensive rules for valid bookmark names but I can say that a bookmark name can't include spaces or begin with a number. If your selected text is a single word then the macro 'could' run without an error but in most cases it will probably fail because of what was selected when the macro started.

The MsgBox lines aren't right either but at least they don't stop the macro from proceeding.

Then you have to ask, what is the ultimate point of the code. Are you thinking it is useful to create a bookmark around a word with a name that matches the word? How is this going to be something useful?

You should look at CoPilot generated code as an opportunity to learn about coding rather than expecting it to actually work. If this is an example of what it can do then it might be rare that it produces errorless code. This could be because of limitations in AI or perhaps because you asked the question in a 'non-optimal' way. Perhaps if you experimented with asking the question in different ways, you could compare the various code outputs to see if there are variants that work as you expected.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Code to copy data from two sheet ,paste into corresponding sheet through cmdbutton jackfruit88 Excel Programming 1 07-08-2022 09:27 PM
paste returns the wrong not the latest cut Peborgh Word 2 11-23-2021 03:31 AM
Copy/Paste of unmodified VBA Code in Word returns an error Error 4605 while trying to copy and paste with same document Ilmari Word VBA 2 05-05-2020 12:08 AM
Copy/Paste of unmodified VBA Code in Word returns an error Copy/Paste error stuart255 Office 5 05-06-2019 02:13 AM
VBA Newbie (Trying to write a code to copy and paste info from one sheet to another) Forum2000s Excel Programming 2 05-07-2017 04:51 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:20 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft