Wait for command to execute

tpeitzme

New Member
Joined
Apr 30, 2010
Messages
7
Hi I am trying to combine a bunch of large documents into one word file. When the files gets too big it seams that the macro will open it and start to write it but will then continue on with the next command before the first one is finished. If I add a sleep command it will get farther into the document but this is such an ugly slow way to get this done.


Do While DSPName <> ""
Selection.TypeText Text:=vbNewLine & DSPName
Selection.Style = ActiveDocument.Styles("Appendix A 2")
Selection.TypeText Text:=Chr(13)
Selection.ClearFormatting
Selection.Font.Size = 8
Selection.Font.Name = "Courier New"
FileContents = ImportData(Folder & DSPName)
Selection.TypeText Text:=FileContents & vbNewLine //Large file to input
Sleep 10 //sleep helps but it waste a ton of time
Selection.TypeText Text:="Done" //Once it hits this input it seems to stop inputting the above text whether it was completed or not
DSPName = Dir()
Loop
 
Last edited:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Ug well it appears the text files have an EOF embedded in the middle some how. This is going to be interesting :(
 
Upvote 0
//Soluition\\ -incase anyone runs into a simaler problem

The line

Selection.TypeText Text:=FileContents & vbNewLine

would fail when it hit special characters it could not type use the commant

Selection.Text = FileContents & vbNewLine

and it will be able to handle special characters
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,855
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top