excel-vba

Word VBA to refresh embedded Excel chart

北战南征 提交于 2020-06-18 11:50:07
问题 I have embedded charts in a Word doc. When I update the data in Excel, so that the chart in the Excel workbook updates, and then go to the Word doc, I can manually select the embedded chart, select Design > Refresh Data, and the embedded chart in Word updates to show the new data. When I try to record the Word VBA to do that, it won't let me do those actions. I've looked everywhere I can think of in Word's object browser. I see that I can identify the embedded chart like this: thisdocument

overwrite existing file excel vba

混江龙づ霸主 提交于 2020-06-18 11:46:06
问题 open_book.SaveAs Filename:="E:\MF\data\" & com_tick_ask & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False This is my code to save a file as xlsx but I want to overwrite an existing file. and close this workbook. Can anyone help... 回答1: Sorry friends for trouble. I got an answer. I just have to put this line of code immediately before my SaveAs statement... Application.DisplayAlerts = False and have to put this line of code immediately after it... Application.DisplayAlerts = True e

overwrite existing file excel vba

元气小坏坏 提交于 2020-06-18 11:45:50
问题 open_book.SaveAs Filename:="E:\MF\data\" & com_tick_ask & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False This is my code to save a file as xlsx but I want to overwrite an existing file. and close this workbook. Can anyone help... 回答1: Sorry friends for trouble. I got an answer. I just have to put this line of code immediately before my SaveAs statement... Application.DisplayAlerts = False and have to put this line of code immediately after it... Application.DisplayAlerts = True e

Printing prime numbers

我的未来我决定 提交于 2020-06-18 11:42:26
问题 I have to print the sequential 25 prime numbers after I ask the user to input a number. The code below indeed does print prime numbers but it prints empty spaces. I can't figure out how to make it print ONLY the prime numbers and no empty spaces. I have this thus far: Public Function IsPrime(value) Dim remainder As Double Dim rounded As Long Dim Max As Long Dim j As Long IsPrime = 0 Max = 1 + Int(value / 2) For j = 2 To Max rounded = Int(value / j) remainder = (value / j) - rounded If

Printing prime numbers

邮差的信 提交于 2020-06-18 11:41:47
问题 I have to print the sequential 25 prime numbers after I ask the user to input a number. The code below indeed does print prime numbers but it prints empty spaces. I can't figure out how to make it print ONLY the prime numbers and no empty spaces. I have this thus far: Public Function IsPrime(value) Dim remainder As Double Dim rounded As Long Dim Max As Long Dim j As Long IsPrime = 0 Max = 1 + Int(value / 2) For j = 2 To Max rounded = Int(value / j) remainder = (value / j) - rounded If

searching for multiple occurrence of a text and changing another text in vba

女生的网名这么多〃 提交于 2020-06-18 11:17:40
问题 I am pretty new at vba. I am searching for a string in excel can also be multiple occurrence and then for each occurrence changing another text if this string is found. but my code is going into infinite loop. How can i achieve that? Here is my code: Private Sub PRODA_Replace_IfNDM_Click() Dim FindWord As String, Found As Range Dim firstAddress As String Dim rslt As Range FindWord = "/*_NDM*" Set Found = Sheets("PRODA").Cells.Find(What:=FindWord, _ LookIn:=xlValues, _ lookAt:=xlPart, _

How to use OR in if statement in VBA

怎甘沉沦 提交于 2020-06-18 10:55:31
问题 Did I use "OR" correctly in my below code. Could someone help me please? If Cells(i, 3).Value = "BRITISH TELECOM" Or "CHRISTIES INTERNATIO" Or "DTAG" Or "IMAGINE COMMUNICATIONS CORP" Then 回答1: No, you didn't: If Cells(i, 3).Value = "BRITISH TELECOM" Or _ Cells(i, 3).Value = "CHRISTIES INTERNATIO" Or _ Cells(i, 3).Value = "DTAG" Or _ Cells(i, 3).Value = "IMAGINE COMMUNICATIONS CORP" Then An alternative would be to use a Select Case statement. These are especially useful if you have many

How to know when a picture is being selected in Excel with VBA? [closed]

孤人 提交于 2020-06-18 10:37:33
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Improve this question I'm new to VBA (1 month), and I can't find how to get my code to know when I select a picture in Excel. I want to be able to autoselect the cell containing the picture if I select the picture instead of the cell. The picture already has the same name as the cell

Copy data from powerpoint textbox to Excel cell

两盒软妹~` 提交于 2020-06-18 09:25:49
问题 I am using macro in MS Excel to import data from textbox in PowerPoint to Excel. It's importing data in text format not able to copy new line characters from textbox Range("a1").Value = pps.Shapes("textbox 1").TextFrame.TextRange.Text Can anyone please suggest alternative solution? 回答1: Recent versions of PowerPoint use Chr$(11) as a linebreak character. It looks like Excel wants a linefeed Chr$(10), so something like this: Range("a1").Value = Replace(pps.Shapes("textbox 1").TextFrame

VBA Excel - Unable to open existing Word Document file

岁酱吖の 提交于 2020-06-18 05:32:54
问题 I have a simple macro that opens a Word Document using Excel. I made sure the Word Object Library is properly referenced but when running this macro it freezes after Documents.Open is called (based on me seeing where it fails in the debugger). I don't know if it is a OLE Automation Error but the macro freezes and I have to force close Excel. Public Const Dir = "C:/Temp/" Public Const File = "temp.docx" Public Sub OpenFile() Dim f As String: f = Dir & File Dim oWord As Object, oDoc As Object